How do you calculate number of valence electrons?
For a main group element, a valence electron is an electron that has the highest principal quantum number, n.
You may tell the number of valence electrons in a main group element by looking at the group number.
For example, bromine atom has 7 valence electrons.
The electron configuration of Br is 1s² 2s²2p⁶ 3s²3p⁶ 4s²3d¹⁰4p⁵.
The electrons with the highest quantum number are the 4s²4p⁵ electrons, and there are 7 of them.
It is easier to refer to the table than to write the electron configuration every time.