The rules governing electron configuration are the Aufbau principle, Pauli's exclusion principle, and Hund's rule:
Aufbau principle: Electrons fill the lowest energy orbitals first.
Pauli's exclusion principle: No two electrons can have the same spin in one orbital. Each orbital can hold a maximum of two electrons with opposite spins.
Hund's rule: Electrons fill empty orbitals singly before pairing up in the same sub-levels.