A covalent bond is formed when two atoms share a pair of electrons, allowing both atoms to achieve a stable electron configuration.