The number of electrons gained/losed or shared by an atom to take part in a bond formation is called valency.
When an atom loses electrons, the number of protons become more than the number of electrons and a positive ion will form, that is called a positive valency.
When an atom attain stability by gaining electrons, the number of electrons become more than the number of protons and a negative ion will form, that is called a negative valency.
Ceratin elements can share electrons to get a stable electronic configuration like carbon.The electron shared in those cases is the valency of that particular element.
Taking an example oxygen having electronic configuration .
It accept two electron to attain octect configuration.
Thus the valency is which is negative due to gaining of electron.