Almost always it's a case of opposites attract. In general metals give away electrons to the non metals on the right side of the periodic table. The metals have a + charge, the non metals have a - charge. Instant attraction. The attraction is pretty powerful: the ionic bond is among the strongest in chemistry.