How did the metal atoms become ions?

Metal atoms became ions by losing electrons to form positively charged ions(cations).

How did the nonmetal atoms become ions?
Nonmetal atoms became ions by gaining electrons to form negative ions(anions).

Very good.

To understand how metal atoms become ions, we need to consider their electron configurations. Metals have relatively low ionization energies, which means it requires less energy for them to lose electrons.

In a chemical reaction, when a metal atom comes into contact with a nonmetal atom, the metal atom tends to lose one or more electrons. This occurs because metals have few valence electrons in their outermost energy level, and losing electrons allows them to achieve a stable electron configuration similar to the nearest noble gas.

When a metal atom loses electrons, it becomes positively charged since it now has more protons than electrons. This positively charged metal ion is also called a cation. The number of electrons lost by a metal atom is equal to the positive charge of the resulting cation.

On the other hand, nonmetals tend to have higher ionization energies, meaning they require more energy to remove an electron. Instead of losing electrons, nonmetal atoms have a greater tendency to gain electrons to achieve a stable electron configuration similar to the nearest noble gas.

When a nonmetal atom gains electrons, it becomes negatively charged since it now has more electrons than protons. This negatively charged nonmetal ion is called an anion. The number of electrons gained by a nonmetal atom determines the negative charge of the resulting anion.

In summary, metals become cations by losing electrons, and nonmetals become anions by gaining electrons. These ion formations occur when metals and nonmetals react with each other, leading to the transfer of electrons between atoms.