A chemical formula gives quite a bit of useful information. For example it indicates the elements present and the relative number of atoms/ions within the compound.
As a result of this, several conversion factors are inherent in chemical formulas including:
mass of compound -> moles of compound -> moles of element -> mass of element
The conversions from mass of compound to moles is done by using the atomic or molar mass and the conversion to moles of element is simply based on the relationship inherent in the chemical formula.