The relative atomic mass (Ar) of an element is the weighted mean mass of its atoms compared with one twelfth of the mass of a carbon-12 atom. It has no units. You read the values from the Periodic Table: H = 1, C = 12, O = 16, Mg = 24 and Ca = 40.
The relative molecular mass (Mr) of a molecule is found by adding up the Ar values of all the atoms in its formula. For water, H2O, Mr = 2 × 1 + 16 = 18. The relative formula mass is found the same way for any compound, including ionic compounds that are not made of molecules. For CaCO3, relative formula mass = 40 + 12 + (3 × 16) = 100.
A bracket multiplies everything inside it. Mg(OH)2 has one magnesium atom, two oxygen atoms and two hydrogen atoms, so its relative formula mass = 24 + 2 × (16 + 1) = 58.
In a balanced equation, find the relative formula mass of each species and multiply by its number in the equation. For 2Mg + O2 → 2MgO, the reactants add up to 2 × 24 + 32 = 80, and the product is 2 × 40 = 80. The totals are equal because mass is conserved.