A simple view of ionic bonding
The importance of noble gas structures
At a simple level (like GCSE) a lot of importance is attached to the electronic structures of noble gases like neon or argon which have eight electrons in their outer energy levels (or two in the case of helium). These noble gas structures are thought of as being in some way a "desirable" thing for an atom to have.
You may well have been left with the strong impression that when other atoms react, they try to organise things such that their outer levels are either completely full or completely empty.
Ionic bonding in sodium chloride
Sodium (2,8,1) has 1 electron more than a stable noble gas structure (2,8). If it gave away that electron it would become more stable.
Chlorine (2,8,7) has 1 electron short of a stable noble gas structure (2,8,8). If it could gain an electron from somewhere it too would become more stable.
The answer is obvious. If a sodium atom gives an electron to a chlorine atom, both become more stable.
The sodium has lost an electron, so it no longer has equal numbers of electrons and protons. Because it has one more proton than electron, it has a charge of 1+. If electrons are lost from an atom, positive ions are formed.
Positive ions are sometimes called cations.
The chlorine has gained an electron, so it now has one more electron than proton. It therefore has a charge of 1-. If electrons are gained by an atom, negative ions are formed.
A negative ion is sometimes called an anion.
The nature of the bond
The sodium ions and chloride ions are held together by the strong electrostatic attractions between the positive and negative charges.
The formula of sodium chloride
You need one sodium atom to provide the extra electron for one chlorine atom, so they combine together 1:1. The formula is therefore NaCl.
Some other examples of ionic bonding
Again, noble gas structures are formed, and the magnesium oxide is held together by very strong attractions between the ions. The ionic bonding is stronger than in sodium chloride because this time you have 2+ ions attracting 2- ions. The greater the charge, the greater the attraction.
The formula of magnesium oxide is MgO.
This time you need two chlorines to use up the two outer electrons in the calcium. The formula of calcium chloride is therefore CaCl2.
Again, noble gas structures are formed. It takes two potassiums to supply the electrons the oxygen needs. The formula of potassium oxide is K2O.