The number of moles in a sample links its mass to its relative particle mass:
moles = mass (g) ÷ relative formula mass Mr (or Ar for an element)
Rearranged, mass = moles × Mr. For example, 11 g of carbon dioxide (Mr 44) is 11 ÷ 44 = 0.25 mol. And 0.5 mol of sodium hydroxide (Mr 40) has a mass of 0.5 × 40 = 20 g. Always check that the mass is in grams before you start.
To count particles, use the Avogadro constant, 6.02 × 1023 per mole: particles = moles × 6.02 × 1023. Going the other way, moles = particles ÷ 6.02 × 1023. So 0.25 mol contains 0.25 × 6.02 × 1023 = 1.5 × 1023 particles (2 significant figures), and 3.01 × 1023 particles is 0.5 mol.
To find the number of particles in a given mass, work in two steps: change the mass into moles, then multiply by the Avogadro constant. To go from particles to mass, reverse the steps.