When a component composed of atoms that easily shed electrons (a metal) reacts with a component composed of atoms that easily gain electrons (a nonmetal), a transfer of electrons usually happens, creating ions. The compound formed by this transfer is stabilized with the electrostatic attractions (ionic bonds) between the ions https://cyanolab.net/about-us/