Metals tend to lose their incomplete outer shell and attain a positive charge and become cations. Non-metals, on the other hand, gain electrons to completely fill their incomplete outer shells and in the process attain negative charge and become anions.
An example is sodium, which has an atomic number of 11 and an electronic configuration of 1s2, 2s2, 2p6, 3s1. Sodium has an incompletely filled outer shell and readily loses an electron to form sodium cation (Na+). This cation readily forms an ionic bond with a non metal that is willing to accept an electron, halides are good examples of that. Chlorine needs just 1 more electron to completely fill its outer shell and accepts electrons from sodium and become the chloride anion. These cations and anions form ionic compound, known as sodium chloride, NaCl.
Hope this helps.