Valency is the combining capacity of an Element. It is the number of electrons an atom of an element can gain,lose or share.
The valency of an atom is equal to the valence electrons, if it is 4 or less.
If it is more than 4, the valency is equal to 8 minus the number of electrons in the outer shell.
Example: Magnesium has electronic configuration 2,8,2. Its valence shell has 2 electrons. As 2 is lesser than 4, the valency of Magnesium is 2.