The atoms of non-metals need to gain electrons to achieve stable arrangements of electrons. They can do this by sharing electrons with other atoms. Each shared pair of electrons strongly attracts the two atoms, forming a 'covalent bond.'
Atoms of elements in Group 7 need to gain 1 electron and so form a single covalent bond. Those in group 6 need to gain 2 electrons and form 2 covalent bonds. Atoms of elements in Group 5 can form 3 bonds and those in Group 4 can form 4 bonds.
Covalent bonds act only between the 2 atoms they bond, and so many covalently bonded substances consist of small molecules. Some atoms that can form several bonds, like carbon, can join together in giant covalent structures.