Valency can be defined as the number of electrons in the valence shell(last shell or ring).
For any element to attain valency, it has to have maximum number of electrons in its valence shell. This can be achieved either by donating its extra electron to another element of by receiving few electrons from another element(s).
Number of electrons in the valence shell to attain stability can be expressed by using the formula 2k2.
where 'k' stands for the place of the shell.
For eg. the number of electrons to attain stability in the first shell will be,
2k2
=2*(1)2
=2*1
=2
By using this formula, we can conclude that the no. of electrons in the valence shell to achieve stability must be, 2,8,18, etc.
So if they give u an element, say chlorine, you have to first think of its atomic number i.e., 17 and its atomic configuration- 2,8,7.
For the third shell, we should actually take 8 as its stability point. Therefore, we can conclude by saying that, chlorine requires 'more' electron to gain stability and that 1 electron is its valency.