Iron is a d block element . the energy difference between the s sub shell of the outermost shell and the d sub shell of the penultimate shell in d block elements is very small. Therefore during compound formation electrons from both these sub shells may be transferred or shared. Hence iron forms compounds with two different valences.