As shown in the table at the right many of the non-metallic elements exist as molecules in which two or more of the atoms are linked by covalent bonds.
 
 Group 15Group 16Group 17
H2N2O2F2
 P4S8Cl2
   Br2
   I2


A covalent bond is a shared electron pair. 
Depending on the atoms involved, more than one electron pair may be shared by the bonded atoms.
 
Single bonds 
(one shared electron pair)
Double bonds
(two shared electron pairs)
Triple bonds
(three shared electron pairs)
 
Bonds form because the energy of the bonded atoms is lower than the energy of the non-bonded atoms.
The difference in energy between bonded and non-bonded atoms is actually a difference in potential energy (energy of position).

The potential energy of a system decreases when two objects that have an attraction for one another are brought closer together.
Thus a ball drops naturally to the earth (and its potential energy decreases) because the ball has an attraction for the earth due to gravity.

The number of electron pairs that are shared between the atoms of a particular element and the number of atoms in a molecule of that element can be rationalised on the basis of a model in which bond formation involves pairing of unpaired electrons

Consider, for example a hydrogen atom with an unpaired electron in a 1s atomic orbital. 
The partial merging of these orbitals on adjacent atoms results in a molecular orbital containing two electrons.
The extent to which the orbitals overlap is determined by the balance of attractive forces that result in bonding and the repulsive forces between the nuclei and the core electrons of the bonded atoms. 

The energy of the bonded atoms is lower than that of the isolated hydrogen atoms because the electrons in the bond are now each close to two nuclei. 
 
The bonding pair has one electron from each atom. A bonding electron pair is usually shown as a line
H•  + •H  H H
(may also be shown as)
H — H
A diagram showing the molecular orbital
occupied by the bonding pair of electrons.