When a metal and a nonmetal exchange electrons to make a cation and an anion, respectively, they can form an ionic compound. The formula of an ionic compound indicates the kinds and number of ions. The number of anions and cations create a compound with an overall charge of zero; in other words, the positive and negative charges are balanced.