Valence electrons

The electrons in any atom can be divided into two types. These are:
core electrons in filled shells.  These electrons are not involved in bonding
valence (outer) electrons in unfilled shells.  These are the bonding electrons.
 
12
 1H2He
3Li4Be 5B6C7N8O9F10Ne
11Na12Mg13Al14Si15P16S17Cl18Ar
19K20Ca21Sc22Ti23V24Cr25Mn26Fe27Co28Ni29Cu30Zn31Ga32Ge33As34Se35Br36Kr
 
The first four periods (rows) of the periodic table are shown.
These contain many important elements.

 
Mg (12 electrons) has
2 electrons in shell 1 (a filled shell)
8 electrons in shell 2 (a filled shell)
2 electrons in shell 3 (incomplete).

Hence Mg has 10 core electrons and 2 valence electrons.

The number of core electrons depends on the period (row) in which the element is found.

Elements in period 2 have 2 core electrons
(equal to the number of elements in period 1).
Elements in period 3 have 10 core electrons (equal to the number of elements in periods 1 and 2).
Elements in period 4 have 18 core electrons
(equal to the number of elements in periods 1, 2 and 3).
 
The Groups in the periodic table are the columns with numbers at the top.
The number of valence (outer) electrons on an atom can be deduced from its Group number.

For main group* elements the number of valence electrons equals the last digit of the Group Number.
*Main group elements are the elements in Groups 1 and 2 as well as the elements in Groups
to
.