According to what i learned in university, the energy of orbitals increases when the principal quantum number n increases. Also, in a given shell, s orbitals have lower energy than p orbitals which have lower energy than d orbitals, which in turn have lower energy than f orbitals.

And according to Aufbau principle: "Electrons fill lowest energy orbitals first."

But when we write the electron configuration of atoms, it goes as follows: 1s 2s 2p 3s 3p 4s 3d 4p 5s 4d 5p 6s 4f 5d 6p 7s 5f 6d 7p

For example, why is 4s filled before 3d? I think i have a big misconception here.

Another question circulating around the same topic is the order of electron removing when we want to form cations. To take as an example, let's take the electronic configuration of the atom Mn and its cation Mn2+

Mn: [Ar] 4s2 3d5

Mn2+ :[Ar] 3d5

Why did we remove electrons from the 4s before the 3d? Shouldn't the order of removing electrons be exactly the opposite pathway of Aufbau principle? And what is exactly the method used to remove electrons from an atom to form its cation?