Question: how do we know how many valence electrons an element has?
Answer: 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.