An ionic bond is formed between an active metal and a nonmetal. The electrons are not shared between the two atoms; instead, the electrons transfer from the metal to the nonmetal.
Metals are electron donors, whereas nonmetals are electron acceptors. Metals have relatively few valence electrons that they can give up, and nonmetals have many valence electrons that they want to keep.
Elements have a tendency to fill up their outer energy levels, thus attaining a more stable electron configuration. Metals, with relatively few electrons in their outer energy levels, want to give electrons away, becoming cations, or positively charged ions. Nonmetals almost have the full complement, so they want to gain electrons from other elements to become negatively charged ions, or anions.