The first electron in both the cases has to "be removed from 3s-orbtials, but nuclear charge of Na is less than that of Mg. Hence I.E. of Na is lower them that of Mg.
After the loss of first electron the electronic con-figuration of {{Na}^{+}} is1${{s}^{2}}2{{s}^{2}}2{{p}^{6}}, i.e., that of noble gas which is very stable and hence the removal of 2nd electron from {{Na}^{+}} is very difficult. In the case of Mg, after the loss of first electron, electronic configuration of {{Mg}^{+}} ions is 1{{s}^{2}}2{{s}^{2}}2{{p}^{6}},3{{s}^{1}}. The second electron to be removed is from 3s orbital which is easier.
Hence I{{E}{2}} of sodium is much larger thanI{{E}{2}}$ of Mg.