The ratio by mass of elements in a compound is determined by the number of atoms of each element and their respective atomic masses.