J.R. S. answered 02/16/22
Ph.D. University Professor with 10+ years Tutoring Experience
The valence electrons are those in the outer-most shell. So, if we take a non-metal like nitrogen, we see it is in group 5A (15) so it has 5 valence electrons. It would prefer to have 8, so it would gain 3 electrons giving it a 2- valence as the anion. Looking at oxygen in group 6A (16), it has 6 valence electrons so would want to gain 2 electrons to get to 8 electrons. This would give it a valence of 2- and so on. The halogens have 7 valence electrons and would gain 1 electron to produce an anion with a valence of 1-.