Magnesium has 12 electrons.........which wud mean that in the 1st energy level(n=1) there r 2 electrons, in the 2nd energy level(n=2) there r 8 electrons and in the 3rd energy level(n=3) there r 2 electrons.......its simple......use the formula 2n^2 where n= 1,2,3,......
so the electron configuration of Magnesium in 2,8,2..................or more precisely 1s2, 2s2, 2p6, 3s2