Molarity is the number of moles per unit of volume. A mole is a measure of the number of molecules in a sample. Because some equations are written in moles instead of density, a conversion may be preferable to work in density directly. The reason equations may be written in moles is to allow for a broader usage of equations, so you can prevent a proportionality constant from varying. An example is the ideal gas law, PV=nRT, where n is the number of moles. Replacing n/V with density would force the proportionality constant R to vary between gases.
Definition of Mole
A mole is a measure of a substance numerically equal in grams to its molecular weight, or molecular mass. For example, the molecular weight of hydrogen is 1.00794 atomic mass units (amu), so a mole of hydrogen weighs 1.00794 grams. A mole of oxygen weighs 15.9994 grams. The reason the values are not precisely equal to 1 or 16 is because molecular weight is an average over an element's isotopes.
Definition of Molarity
Molarity is a measure of concentration: moles of solute per liter (L) of solvent. (This is not to be confused with "molality," which is moles per kilogram of solvent.) Molarity is represented with a capital M. For example, 12.011 grams of graphite dissolved in a liter of water would be said to have a concentration of 1.0000M, or a molarity of 1.0000.
An essential step in converting between density and molarity is to have access to the molecular weights of the elements. Fortunately, periodic tables tend to include them, listed below each element symbol.
Next, the molecular weight of the solute has to be determined. Suppose the solute is sodium chloride (NaCl). The molecular weight of NaCl is 22.990 (Na) + 35.453 (Cl) = 58.443 amu.
So if 30 grams of NaCl have been dissolved into solution, the number of moles of solute is 30g / (58.443g per mole) = 0.5133 moles.
Suppose there is 500mL of solvent. Remember that molarity is measured per liter (L) of solvent. So the molarity is 0.5133 moles / 0.5L = 1.027M.
Converting back to density is a matter of multiplying by (58.443g per mole) to get 60.02g/L.