Sharing electrons between atoms to fill each atom's s and p subshells results in the formation of a covalent bond. A sigma bond is formed when the electron shells overlap end-to-end so that the region of maximum density is in alignment with the two atoms. A Pi bond is formed when p orbitals overlap giving a region of highest electron density "above" or "sideways from" the axis between the bonding atoms.
All atoms "want" to have a filled set of s and p electron subshells, just as the noble gases do. There are two ways to do this: form an ion, or share electrons with another atom. Sharing electrons with another atom results in the formation of a covalent bond.
For the alkali metals, alkaline earth metals, and some of the transition metals, it is easier to lose electrons to achieve a noble-gas configuration than gain enough to fill their s and p subshells. Elements in the alkali metals lose one electron; those in the the alkaline earth metals lose two.
Atoms on the right side of the Periodic Table must gain electrons to reach a noble gas configuration. Because the s and p subshells (which contain a total of eight electrons) make up most atoms' valence electrons, each atom must make enough bonds to have eight valence electrons. This is called the octet rule. Some atoms, however, do not obey the octet rule: boron, for instance, only makes three bonds, and atoms past phosphorus can make more bonds than necessary to satisfy the octet rule.
The first way for these atoms to gain electrons is simply take them from another atom; for example, chlorine wants to gain one electron to attain an argon configuration, and one way it can do this is to steal sodium's electron. In this way, both atoms are happy, and the attraction between the positive ion (the cation) and the negative ion (the anion) will hold the atoms together. Such a bond type is called an ionic bond. The halogen needs only one electron; each column to the left needs one more electron to complete its subshells.
An ion will bond to as many other ions as necessary to neutralize its electric charge--for instance, magnesium forms a 2+ ion, so it will bond with two chlorine ions. Oxygen will form a 2- ion, so it needs to bond with only one magnesium 2+ ion. Iron sometimes forms a 3+ ion, and since oxygen has a 2- charge, two iron cations must bond with three oxygen anions, giving a molecule of Fe2O3.
Two atoms that want to gain electrons may also share valence electrons; two fluorines will bond, sharing one electron each, so each atom seems to "think" that it has eight, giving full s and p subshells. This type of electron-sharing bond is called a covalent bond. Atoms may share more than one electron pair: in the O2 molecule, two electron pairs are shared, and three electron pairs are shared between the nitrogen atoms in the N2 molecule. Covalent bonds involving the sharing of more than three pairs of electrons are rare.
There are two types of covalent bonds: sigma (σ) and pi (π) bonds. Sigma bonds occur when s orbitals, p orbitals pointing along the axis to the other bonding atom, or hybridized orbitals collide and overlap; the region of maximum electron density is between the two bonded atoms and lies along the axis between them. Single-order bonds are always σ bonds. Sigma bonds are like taking the index finger from each hand and pointing them directly at each other, so one fingertip touches another. Just as you can rotate your fingers without losing contact, bonded atoms can rotate freely about a sigma bond.
Pi bonds occur when p orbitals (usually those left over from orbital hybridization) perpendicular to the axis of bonding overlap; in this case, the region of highest electron density is "above" or "sideways from" the axis between bonding atoms. It is important to note that hybridized or s orbitals never make π bonds. Pi bonds make up the second bond in a double bond and the second and third in a triple bond. Pi bonds are like pointing two fingers at the ceiling and moving them sideways until they touch. Unlike sigma bonds, pi bonds cannot rotate and maintain the bond; you can see this in our finger model, as turning your fingers out of alignment breaks the connection. Therefore, double or triple-bonded atoms cannot rotate relative to each other.