The valency of an element is the number of electrons it gains or loses or shares to attain the noble gas configuration. In other words, how any electrons should an element lose or gain or share to have a completely filled outer electronic shell.
Iron (Fe) has an atomic number of 26, i.e. has 26 electrons.
Its electronic configuration is given as:
`1s^2 2s^2 2p^6 3s^2 3p^6 3d^6 4s^2`
The energy of 4s and 3d orbital is similar (4s has slightly higher energy). Also note that the 3d orbital has 1 electron pair, rest of the electrons are unpaired.
Now, iron exhibits 2 valence states of +2 and +3.
When iron loses the 2 4s electrons, it attains a valency of +2. Sometimes, iron will also lose one of the paired electrons from 3d orbital, leaving the entire 3d orbital filled with unpaired electrons (which provides a more stable configuration). In this case, its valency will be +3.
Hope you got your answer