Writing the formulae for ionic compounds

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 simplest relative number 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.

Therefore 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.
use the simplest whole number ratio of anions to cations.  
 
Calcium bromide is CaBr2 as there must be two Br for each Ca2+.
Aluminium sulfate is Al2(SO4)3 because there must be three SO42– for every two Al3+.

Note that if the formula unit contains more than one of the polyatomic ion, the entire polyatomic ion formua must be enclosed in brackets.