All substances are described by their formulae, which are used to write balanced chemical equations. Writing the formula for an ionic compound requires knowledge of the charges on its ions.

The formula of an ionic compound shows the relative numbers of the ions it contains. For example:

- the formula for sodium chloride is NaCl - it shows that for every Na
^{+}ion there is one Cl^{-}ion - the formula for magnesium chloride is MgCl
_{2}- it shows that for every Mg^{2+}ion there are two Cl^{-}ions

The formula for an ionic compound must contain the same number of positive and negative charges. This is so that the charges are balanced and the compound is neutral overall. Here are some examples.

Sodium chloride contains Na^{+} and Cl^{-} ions:

- this is one positive charge and one negative charge
- the charges are balanced (add up to zero)
- so the formula is
**NaCl**

Magnesium oxide contains Mg^{2+} and O^{2-} ions:

- this is two positive charges and two negative charges
- the charges are balanced
- so the formula is
**MgO**

Aluminium oxide contains Al^{3+} and O^{2-} ions:

- this is three positive charges and two negative charges
- to balance we need, two Al
^{3+}ions and three O^{2-}ions - so the formula is
**Al**_{2}O_{3}