Why do atoms form chemical bonds?
All neutral atoms are unstable, except for the noble gases in group 18/VIIIA. All neutral atoms, except the noble gases, form bonds in order to become stable.
Neutral atoms are unstable because they do not have filled valence shells, which for most atoms means having 8 valence electrons (an octet), except for hydrogen and lithium, whose valence shells are full with 2 valence electrons (a duet).
In order to achieve a filled valence shell, some atoms (metals) transfer electrons to other atoms (nonmetals), forming oppositely charged ions, which undergo ionic bonding. The electrostatic attraction between the oppositely charged ions is the ionic bond.
In the diagram below, a neutral sodium (Na) atom transfers its single valence electron to the valence shell of the neutral chlorine (Cl) atom. The next lower energy shell in the now sodium ion has 8 valence electrons, and the valence shell of the now chloride ion has 8 valence electrons.
Some atoms, usually nonmetals, achieve a filled valence shell by sharing two or more valence electrons. This is called covalent bonding.
In the diagram below, the areas of overlap represent the covalent bonds between the atoms. Methane and water have only single covalent bonds, but carbon dioxide has double covalent bonds between the central carbon atom and the oxygen atoms. The red dots and the blue exes represent the valence electrons.