# Why do PES graphs list 4s after 3d? [duplicate]

Coming straight off of some electron configuration worksheets, our teacher started to teach us how to read photoelectron spectroscopy (PES) graphs and I'm having a bit of trouble with the two.

During the previous lecture on electron configuration, we were told that electrons occupied the most stable energy level available. That came in this order: 1s, 2s, 2p, 3s, 3p, 4s, 3d, 4p, 5s, 4d, etc. But then, during the photoelectron spectroscopy lecture, we were told that the 3d electrons have higher ionization energy than the 4s electrons and, in fact, that this pattern continues, just counting up the orbitals: 1s, 2s, 2p, 3s, 3p, 3d, 4s, 4p, 4d, 4f, etc. Why do electrons fill orbitals in the former pattern, but leave orbitals in the latter pattern?

Why would the 4s orbital fill before the 3d if it is less tightly held by the nucleus, and thus less stable?

I assume I have been taught some simplified versions and my teacher has my interests at heart, but I'm a bit confused.

For a given atomic kernel, the orbitals energies are not fixed like a set of shelves. Their energy depends on filling themselves and also on filling the other orbitals by electrons, because of kernel shielding and mutual repulsion. The mutual energy is $$4\mathrm{s} \lt 3\mathrm{d}$$ when empty. But as kernel charge gets increased and $$\mathrm{4s}$$ and then $$\mathrm{3d}$$ are being filled, their energy order gets switched.
The typical case is the 3d energy drop $$\ce{K -> Ca -> Sc}$$, where the order is:
$$\mathrm{K: 4s \lt 4p \lt 3d}$$ $$\mathrm{Ca: 4s \lt 3d \lt 4p}$$ $$\mathrm{Sc: 3d \lt 4s \lt 4p}$$