The molecular mass of the compound (such as 18 for a water molecule) in grams is 1 mole of that substance (thus 18 grams of water is 1 mole of water).
Number of moles = Mass in grams / Molecular mass of chemical
So if I had 72 grams of water, I would divide by the molecular mass (18) to get the number of moles I had: 72/18 = 4