The valence or oxidation state of an element is associated with the electronic configuration and is determined by the electrons present in the valence shell. The number of electrons which an atom loses or gains or shares with another atom to attain the noble gas configuration is defined as its valency. In an ionic compound, the oxidation state is equal to the charge on the ion, e.g., in NaCl, the charge on the sodium is +1 and the oxidation state is also +1. In contrast, the charge on an atom in a covalent compound never approaches the charge implied from the oxidation number, e.g., in CCl4, the oxidation state of carbon is +4, however, the charge on the carbon atom is considerably less.
The valency of atoms of s-block and p-block elements are given as the number of valence electron or eight minus the number of valence electrons. Whereas, in d-block and f-block elements valency is determined not only based on valence electrons but also on d and f orbital electrons. However, the valencies of these d and f block elements are 2 and 3.
Two compounds, Na2O and F2O have a similar molecular formula. However, in F2O, the electronegativity of F is more than oxygen. Each of F atoms attracts one electron from oxygen i.e. F shows -1 oxidation state and O show +2 oxidation state. Whereas, for Na2O, oxygen is highly electronegative in comparison to sodium atom. So, oxygen attracts two electrons from each sodium atom showing -2 oxidation state and Na has a +1 oxidation state. Thus, the oxidation state of the element represents the charge possessed by an atom due to loss or gain of electrons.