The number of moles is a measure used in chemistry to quantify the amount of substance. It connects the mass of a substance to the number of atoms, molecules, or ions it contains, allowing for calculations involving gases under ideal and real conditions.