Actually we don't call energy shells any more but energy levels as it is hard to locate the electrons' exact location in each level.
Now the the lowest the energy most stable the atom is. Therefore the energy levels closest to the nucleus are filled first to keep the energy of the atom lowest to achieve most stable state.