For metals, it is equal to the number of electrons in the outermost shell of their atoms, and for nonmetals it is eight minus the number of electrons in the outermost shell. Elements lose or add electrons only to become more stable.
To calculate valency you must have to calculate the outer shell electrons for that you have to know electron configuration. When you say 20 you are talking about Calcium. The electronic configuration of Ca is [Ar]4s2 or you can write in this way(junior level) K=2, L=8, M=8, N=2. In the both cases the outermost electron number is 2. So if it loses 2 electrons then it will obtain stable noble gas ( Ar) configuration