a d subshell can hold 10 electrons. The order, a.k.a. the Aufbau principle, says the lowest energy subshell must be filled first, then the next lowest, following the sequence of increasing subshell energies. i.e. 1s > 2s> 2p > 3s > 3p > 4s 3d > 4p > 5s > 5d. Therefore, a 4s subshell will have lower energy than a 3d subshell and that is why it is filled first.