Ionic compound formula from name

Ionic compounds exist as extended lattices where each anion is surrounded by cations and each cation is surrounded by anions. 
A portion of the lattice of sodium chloride is shown at the right.

Roll your mouse over this image to see that the sodium cation at the center of the lattice is surrounded by chloride anions.
 
The formula of an ionic compound represents the relative numbers of cations and anions in the lattice. 
Because the lattice has no overall charge, the total positive charge on the cations must equal the total negative charge on the anions.
 
Thus sodium chloride is NaCl because there must be equal numbers of Na+ and Cl.
The sodium oxide lattice must have twice as many Na+ as O2– in order to equalise the charge, and the formula for sodium oxide is Na2O.

When writing the formula of an ionic solid from its name, care must be taken to include appropriate numbers of cations and anions so that there is no overall charge.