, the valency of an element measures its ability to combine with other elements. The number of electrons within the outer shell of the element determine its valency. To calculate the valency of an element(or molecule, for that matter), there are multiple methods.
The first(and easiest) is simply to consult the periodic table. The elements are sorted into groups, and the elements in the groups(1–8 respectively) have the same valency as others in their group. For example, all of the elements in group 8 have eight electrons(high stability).
The second method is to look at the total number of electrons, and then calculate the valency(if you don’t know, remember to look at the atomic number - the number of electrons is always equal to the number of protons). The valency of an atom is equal to the number of electrons in the outer shell if that number is four or less. Otherwise, the valency is equal to eight minus the number of electrons in the outer shell. Once you know the number of electrons, you can easily calculate the valency. All atoms other than hydrogen have two electrons in the first electron shell, and up to eight electrons in each succeeding electron shell. For example, the atomic number of chlorine is 17, making the configuration of electrons would be 2, 8, and 7 - meaning, the valency of chlorine is 7. Oxygen has eight electrons, two in the first shell and six in the outer shell, giving it a valency of 2.
You can also calculate the valency of multi-element molecules the same way. For example, to determine the valency of, say, phosphorus tetraoxide, you would multiply the total valency of the four oxygen atoms (valency 2) and subtract that from the valency of the phosphorus atom (valency 5) to get the solution of 3.