An atom's electrons are layered, and only the outermost layer meets neighboring atoms. Chlorine has 17 electrons arranged 2, 8, 7. The inner 10, the core electrons, are held tightly close to the nucleus and never take part in ordinary reactions. The outer 7 are the valence electrons, and they are what chlorine uses to bond.
The columns of the periodic table are built on this outer count, so for main-group elements you can read it straight off. Lithium, sodium and potassium (group 1) each have 1 valence electron, and each reacts with water by giving it up. Fluorine, chlorine and bromine (group 17) each have 7, and each tends to gain one more. Atoms with 1, 2 or 3 valence electrons usually lose them; atoms with 5, 6 or 7 usually gain or share enough to reach 8; carbon, with 4, shares.
The group shortcut has limits. It works for groups 1, 2 and 13 to 18, not for the transition metals in between. Iron can lose 2 or 3 electrons, forming Fe2+ or Fe3+, because some of its inner d electrons are close in energy to its outer ones. At the other end, noble gases have a full outer shell (8, or 2 for helium), which is why they rarely react at all.
Think of it like this. Valence electrons are like the outer coat of paint on a wall: anything that leans on the wall touches only that coat, however many layers lie beneath. Bonding is contact between atoms, so only the outer shell's electrons take part. Unlike paint, what matters is how many electrons the outer layer holds, not how thick it is.
Core idea. Only an atom's outermost electrons take part in bonding, so their number, which is the same all the way down a group, predicts how many bonds an atom forms and which ion it becomes.