The equation for finding how many moles are in a substance is
moles = mass / relative formula mass,
where mass is measured in g.
The r.f.m. (relative formula mass) is found by adding together all of the atomic masses of the elements in a substance.
e.g. CO2 (carbon dioxide) has 1 atom of carbon and two atoms of oxygen.
The relative atomic mass of carbon is approximately 12.
The relative atomic mass of oxygen is approximately 16.
12 + (2 x 16) = 44
The r.f.m. of carbon dioxide is 44.
You would then divide the mass of the substance (how much there is of it) by its r.f.m. to find the mole number.