The relative formula mass (Mr) of a compound is the sum of the relative atomic masses (Ar) of all the atoms in the numbers shown in the formula. You find the Ar values on the periodic table. In these examples: Mg = 24, O = 16, C = 12 and Ca = 40.
For MgO: 24 + 16 = 40, so the Mr is 40. For CaCO3 there are three oxygen atoms, so: 40 + 12 + (3 × 16) = 100.
In a balanced equation, the sum of the Mr values of the reactants in the quantities shown equals the sum of the Mr values of the products. For 2Mg + O2 → 2MgO the reactants give (2 × 24) + 32 = 80 and the products give 2 × 40 = 80.
You can also find the percentage by mass of an element in a compound. Multiply its Ar by the number of atoms of that element in the formula, divide by the Mr of the compound, then multiply by 100. For magnesium in MgO: 24 ÷ 40 × 100 = 60%.