Covalent bonds form when atoms share their valence electrons with other atoms to become a more stable molecule. Atoms share their electrons in order to completely fill up their outer-most layer — the valence shell. Two atoms that are covalently bonded have less energy than the individual atoms, making the bonded atoms more stable.
Atoms form covalent bonds as a result of the Octet Rule. The Octet Rule states that all atoms in a molecule need to have eight electrons in their valence shell. This rule can be satisfied by sharing, losing or gaining electrons. A covalent bond allows atoms to satisfy the Octet Rule via sharing.
The reason atoms in covalent bonds satisfy the Octet Rule through sharing rather than losing or gaining electrons is because covalent bonds form between atoms with similar electronegativities. Electronegativity measures the tendency of an atom to attract electrons. Atoms with similar electronegativities are more willing to share electrons than those with different electronegativities.
Up to three covalent bonds can form at one time in a molecule. In a single bond, one pair of electrons is shared between two atoms. A double bond shares two pairs of electrons; it is stronger than a single bond, but it also creates a less stable molecule because it is more reactive. The triple bond shares three pairs of electrons, making it the least stable covalent bond.