Atoms with fewer than four valence electrons will seek to give them away. The easiest combinations are the ones that use the least amount of energy. To be most stable, the combination would have a full outer shell of eight electrons. So an atom with two valence electrons would look for one atom with six valence electrons, or two atoms with seven valence electrons each to give its two electrons and form full outer shells.
Atoms with five to seven valence electrons will use less energy gaining electrons to complete the outer shell than it would take to give them away. An atom with five valence electrons would combine with three atoms having one valence electron each, one atom with one valence electron, and one atom with two valence electrons, or one atom with three valence electrons to form combinations with full eight electron outer shells.
An atom with four valence electrons is going to use the same amount of energy giving away electrons as it would getting them. So it can combine either way, depending on what valence electrons are needed by the other atoms that you are trying to combine them with. An atom with eight valence electrons is stable. It has a complete outer shell, so it doesn't need to gain or give away electrons.
The periodic table of elements will show you the configuration of the electrons in the elements shells. The atomic number of the atom will also tell you the number of valence electrons, if you know how many electrons make a full shell. For example, chlorine has an atomic number of 17. The first shell would have two electrons, the next shell eight, leaving seven for the last shell. So it would have seven valence electrons. The group that the element is in can also help you see the number of valence electrons.