Ionic bonding occurs when a metal atom transfers electrons to a non-metal atom to form ions. The ions have full outer electron shells, making them stable. The positively charged metal ions are attracted to the negatively charged non-metal ions, forming an ionic bond. To determine the formula of an ionic compound, you write the symbols of the elements, determine the charge of each ion, and balance the ions so the total charge is zero. This gives the ratio of ions used to write the chemical formula. For example, sodium oxide has a 2:1 ratio of sodium and oxide ions, so its formula is Na2O.