How does expansion of electron shells work?
You're right! The 4s subshell is filled before 3d. Electrons fill the shell   with least energy first and the 4s shell has a lower energy than the 3d subshell.
Use the Aufbau Principle to find the shell with least energy. 

Basically it says that shells with a lower n+l (n and l are the principal and azimuthal quantum numbers) value are filled first. 
If two shells have the same n+l value, then the shell with lower n is filled first.
There are a few exceptions to this rule - Copper, Chromium, Palladium, etc.

Reason: n+l gives the number of nodes in an orbital. The more the number of nodes, the less stable the orbital and so the higher the energy.
Valence shells are filled in the s and p blocks. The inner shells are filled in the d and f blocks.