The molecular formula of a compound can be found if you have the percent composition of each element on the compound and the molar mass.
We will use the following example to help explain:
A unknown organic compound is composed of 40.0% C, 6.7% H, 53.3% O. the molecular mass of this unknown compound is 180 amu. What is the molecular formula of the compound?
1) First you have to to find the empirical formula of the compound.
Assume you have 100 g of the compound. This allows you to convert the percentages easily to a manageable number.
In a 100 grams there would be 40.0 grams of carbon, 6.7 grams of hydrogen and 53.3 grams of oxygen.
2) Find the moles of each element in the unknown compound.
Divide the masses of each element by the molar mass of each element. You can look up each element's average mass on a periodic table.
40.0 grams C x 1 mole / 12.01 g C = 3.33 moles C
6.7 grams H x 1 mole / 1.008 g H = 6.65 moles H
53.3 grams O x 1 mole / 15.99 g O = 3.33 moles O
3) Write a "skeleton" chemical formula using the number of moles found for each element. Write the chemical symbol of each element and use the moles calculated in step 2 as the subscript for each element in the chemical formula.
C3.33 H6.65 O3.33
4) To find the emprical formula, divide the number of moles of each element by the lowest number of moles of any element.
C3.33/3.33 H6.65/3.33 O3.33/3.33
C1 H2 O1
* If the subscripts are not whole numbers we must find a multiple of these subscript that will give us a whole number.
5) Calculate the molar mass of the empirical formula.
C: 1 x 12.01 = 12.01
H: 2 x 1.008 = 2.016
O: 1 x 15.00 = 15.99
6) Divide the molar mass of the unknown compound by the molar mass of its empirical formula. Multiply the subscripts in the empirical formula by this factor.
180 / 30.02 = 6
C1 H2 O1 x 6 = C6 H12 O6
C6 H12 O6 is the molecular formula for glucose.