Look at the orbitals s,p,d,f.
Basically, the s, p, d, and f orbitals are part of the electron shells, and by looking at the periodic table, one can deduce the spdf configuration (e.g.
Based on this, the more orbitals it has, the higher the energy level.
Hope this helps!
So, in this case, Mg would have 3 energy levels.