How do you know how many valence electrons an atom has?
A simple way to do it is to use the periodic table itself. If you use the "main group number," then the number of valence electrons (for neutral atoms) is the number of the column. If you don't know what the main group columns are, see the link below. For example, Nitrogen is in main group number 5. That means it has 5 valence electrons. Anything in that entire column will be the same. Helium has 8 valence electrons because it is in main group 8. Any atom in that entire column will have 8 valence electrons.
If you have access to a computer when you are trying to figure it out, the dynamic periodic table that I linked is a huge help. Simply hover your mouse over an element and the preview window will display the atomic number at the top left and the electron shells at the top right. Using Nitrogen again, it lists Nitrogen as 7 on the top left and then show 2 and 5 at the top right. This means that Nitrogen has two electrons in the first electron shell and 5 valence electrons. Check any element and the bottom electron number listed is the number of valence electrons.
If you aren't working with an interactive table or elements in the main groups, then you have to count how many electrons are present and then organize them into their proper electron shells and orbitals. The formula for how many electrons that can exist within a shell is Electron capacity = 2n^2 where n is the shell number. For example the 3rd shell can hold 18 electrons. Then the electrons need to be placed in orbitals of those shells. First orbital holds 2, second holds 6, third holds 10. They then get filled so that the lowest energy orbitals get filled first.
Basically, if you have an atom like Sulfer, you take its 16 electrons and start placing them in shells and orbitals until you get a remainder. That is your valence electron number. 2 go in the first shell. 8 go in the next shell. 6 to go. Third shell can take up to 18, so 6 is your valence electron number.
The website mentioned below has a detailed explanation.
"For neutral atoms, the number of valence electrons is equal to the atom's main group number. The main group number for an element can be found from its column on the periodic table. For example, carbon is in group 4 and has 4 valence electrons. Oxygen is in group 6 and has 6 valence electrons."