The number of unpaired electrons in an atom's outermost shell is known as valency.
hydrogen have 1 valency because it have only one electron in its outer most shell.
Oxygen have 2 valency the atomic number of oxygen is 8 from spdf for oxygen1s^2
2s^2 2p^4 when you arrange p orbital 2 electron are remain unpaired. So it have 2 valency
like this valancy of carbon is 4.
valancy of nitrogen is 3