Ionization energy is the energy required to remove the most loosely bound electron from an atom. As the nuclear charge of an atom increases and the size of an atom decreases, the ionization energy increases, as more energy is required to remove an electron. Magnesium atom has a smaller radius and higher nuclear charge than a sodium atom, thus more energy will be required to remove the electron from the same orbital (3s), making the first ionisation energy of magnesium higher than that of sodium.