To calculate the molar mass of a substance, add up the atomic masses of all the atoms that make it up. For example, the molar mass of water is (2 x 1.008) + 16.000 = 18.016 g/mol.
Once you know the molar mass of a substance, you can use it to calculate the number of moles in a given mass of the substance. For example, if you have 10 grams of water, you would divide 10 by 18.016 to find that there are 0.555 moles of water.
Conversely, if you know the number of moles of a substance, you can use the molar mass to calculate the mass of the substance. For example, if you have 0.555 moles of water, you would multiply 0.555 by 18.016 to find that the mass of the water is 10.0 grams.