A covalent bond is formed when two atoms share one or more pairs of electrons to achieve a stable electron configuration.