in it's ground state, carbon has the electron configuration of 1s2 2s2 2p2
it has two half-filled orbitals in the 2p subshell, which leads us to expect it to form 2 bonds instead of 4 as it only has 2 unpaired electrons
but there's only a small energy difference between 2s and 2p subshells
it makes it easy for an electron to be promoted from the 2s to the 2p, which creates 4 atomic orbitals with unpaired electrons
therefore, carbon has a valency of 4 and can form 4 bonds