Every element has a chemical symbol, such as C for carbon, Fe for iron and Na for sodium. The symbol is used as the formula of any element that exists as single atoms. That includes metals, carbon and the noble gases, so helium is He, neon is Ne and argon is Ar.
Some non-metal elements exist as molecules of two atoms joined together, so the formula shows a small lowered number. Hydrogen is H2, nitrogen is N2, oxygen is O2, and the Group 7 elements are F2, Cl2, Br2 and I2. Each of these molecules has two atoms.
The formula of a covalent compound shows the atoms in one molecule. Water, H2O, has two hydrogen atoms and one oxygen atom. Methane, CH4, has one carbon atom and four hydrogen atoms. Ammonia, NH3, has one nitrogen atom and three hydrogen atoms, which is 4 atoms in total.
An ionic compound is a giant lattice of ions, not separate molecules. Its formula shows the simplest ratio of ions. In NaCl the ratio of sodium ions to chloride ions is 1 : 1. In CaCl2 there is one calcium ion for every two chloride ions.