Ionization energy, I, is the energy required to remove an electron from a gaseous atom, isolated and in its ground state. The electrons are attracted to the nucleus and it is necessary to provide energy to start them up. The electrons in the last shell are always lost, as they are the ones that are weakest attracted to the nucleus. $$Mg(g) \rightarrow Mg^{+}(g)+1e^{-}$$ This equation represents the first ionization of Mg and requires $I_1$=738 kJ/mol.

It is possible to continue removing electrons from the ion $Mg^+$ obtaining the $Mg^{2+}$. This second ionization always requires more energy than the first ($I_2$=1451 kJ/mol).

$Mg^{2+}$ has the same electronic configuration as Ne, making it relatively easy to form this ion. However, trying to remove more electrons from magnesium has a much higher energy cost, observing a very significant increase in the third ionization energy.

Now we are going to see how ionization energies vary throughout the periodic table.

• Going down a group the ionization energy decreases . Electrons enter layers further and further away from the nucleus, being less and less attracted, which facilitates their extraction from the atom. Let's look at an equation, although only exact for hydrogen, it gives us an approximation to the ionization energy of polyelectron atoms: I=R_H\frac{Z_{ef}^2}{n^2} \end{ equation} The going down in a group n increases while the effective nuclear charge changes little (increases slightly), resulting in a significant decrease in ionization energy.
• As we move to the right in one period the ionization energy increases , due to the significant increase in the effective nuclear charge, with no change in n.

Now we are going to analyze some exceptions. Aluminum has less ionization energy than magnesium because a 3p electron is more energetic than a 3s, and therefore easier to pull off. Sulfur has less ionization energy than phosphorus because it begins to fill one of the orbitals in the 3p subshell. The repulsion between the two electrons entering the same orbital makes their removal easier, compared to phosphorus, which has the entire p subshell half-occupied.