The empirical formula of a compound is the simplest whole-number ratio of the atoms of each element in it. It can be worked out from the masses of the elements that combine, or from the percentage composition by mass.
First divide the mass (or percentage) of each element by its relative atomic mass. This gives the relative amount of atoms of each element, in moles. Then divide every answer by the smallest number to get a ratio, and if needed multiply to turn it into whole numbers.
Example 1: 2.4 g of magnesium combines with 1.6 g of oxygen. Magnesium: 2.4 ÷ 24 = 0.1. Oxygen: 1.6 ÷ 16 = 0.1. The ratio is 1 : 1, so the formula is MgO.
Example 2: 5.6 g of iron combines with 2.4 g of oxygen. Iron: 5.6 ÷ 56 = 0.1. Oxygen: 2.4 ÷ 16 = 0.15. Dividing by the smallest gives 1 : 1.5. Multiply both by 2 to get the whole-number ratio 2 : 3, so the empirical formula is Fe2O3.