The formula of a covalent network or ionic compound gives the simplest ratio of atoms/ions in the substance. Sometimes the name of the compound gives information about the formula of that compound.
You can work out the molecular formula from the empirical formula, if you know the relative mass formula (M r) of the compound. Add up the atomic masses of the atoms in the empirical formula.