The relative formula madd of a compound comes from the total mass of all of the elments within the compound.
So in the case of calcium carbonate (CaCO3) we have;
1 x Ca
1 x C
3 x O
So we first need to know the relative mass nnumber (Mr) of these individual elements. This information comes from the periodic table and is determined by the number of protons + neutrons in an atom.
Mass number = protons + neutrons
So if we look at the elements in our compound we have;
20Ca40 6C12 8O16
In each case the mass number is the bottom right number (in bold), we can now calculate our relative formula mass using these numbers so we have;
Ca(1 x 40) + C(1 x 12) + O(3 x 16)
= 40 + 12 + 48
= 100 g/mol
The units of relative formula mass are g/mol, which tells us that 1 mole of CaCO3 has a mass of 100 g.