Bonds are formed between atoms because electrons from the atoms interact with each other. Many elements are most stable when they contain eight electrons in their valence shell. Atoms which have less than eight valence electrons bond together to share electrons and complete their valence shells. Two main types of chemical bonding are: ionic bonding (between ions) and covalent bonding (between atoms).
Ionic bonding- In ionic bonding, electrons are completely transferred from one atom to another. In the process of either losing or gaining negatively charged electrons, the reacting atoms form ions. The oppositely charged ions are attracted to each other by electrostatic forces, which are the basis of the ionic bond.
Covalent Bonding- The second major type of atomic bonding occurs when atoms share electrons. As opposed to ionic bonding in which a complete transfer of electrons occurs, covalent bonding occurs when two (or more) elements share electrons. Covalent bonding occurs because the atoms in the compound have a similar tendency for electrons (generally to gain electrons). This most commonly occurs when two nonmetals bond together. Because both of the nonmetals will want to gain electrons, the elements involved will share electrons in an effort to fill their valence shells.