Actually, iron does not have 8 valence electrons per se, it only has 2, but you could say that it has 8 - here's why.
Remember that valance electrons are the electrons located in the outermost shell of an atom. If you take iron, its atomic number is 26, which means that a neutral iron atom has 26 electrons.
The electron configuration of iron is
Iron's outermost shell is the n = 4 shell, the
Transition metals however can use electrons located in their inner shells as valence electrons as well. For iron, when the two electrons located in the 4s subshell are removed, it has a +2 oxidation state and this electron configuration
Now the n = 3 becomes the outermost shell; iron can lose electrons from this shell as well, more specifically from the the 3d subshell which holds 6 electrons.
When one electron from the 3d subshell is removed, iron has a +3 oxidation number and the electron configuration
+2 and +3 are the most common oxidation states of iron, but it can have oxidation states ranging from -2 to +6.
Read more about iron's valence electrons here: