Step 1 - Understanding the relation between empirical and molecular formulae
The empirical formula expresses the least possible proportion between the elements in a chemical compound. The molecular formula, on the other hand, expresses the exact number of atoms of each kind in the molecule.
Let's see an example. The molecular formula of glucose (sugar) is C6H12O6. Note that this is not the least possible proportion, because all the numbers coulb be further divided by six: CH2O.
CH2O, therefore, would be the empirical formula of glucose. Now, there's another molecule, sucrose, which has the molecular formula C11H22O11. Note it can also be reduced to CH2O if we divide all numbers by 11.
The empirical formula, therefore, is never sufficient to understand the structure of the substance (how many atoms of each kind) and cannot be used to differentiate between two substances.
Step 2 - Obtaining the molecular formula from the empirical one
As you may have noted in the examples before, the molecular formula is always a multiple of the empirical formula.
We could write both glucose and sucrose as CxJH2xOx. When x=6, the molecule is glucose (C6H12O6); but if x=11, the molecule is sucrose (C11H22O11)
Let's apply this same reasoning to discover the molecular formula of nicotine. We already know its empirical formula: C5H7N. Since the molecular formula is always a multiple, let's write it as:
Now, let's find the molar mass of this molecule. Remember the molar masses of the elements are C 12g/mol; H 1 g/mol; N 14 g/mol. Therefore:
We also know that the molar mass of nicotine is 162.26 g/mol. So:
Therefore, x=2. Substituting in the formula C5xH7xNx, we get the molecular formula of nicotine: