Here are the general trends:
Metals: Metals tend to lose electrons during chemical reactions, becoming positively charged ions called cations. This is because metals have relatively low electronegativity, which means they have a weaker attraction for electrons. By losing electrons, metals achieve a more stable electron configuration with a full outer energy level.
Nonmetals: Nonmetals, on the other hand, tend to gain electrons during chemical reactions, becoming negatively charged ions called anions. This is because nonmetals have relatively high electronegativity, which means they have a stronger attraction for electrons. By gaining electrons, nonmetals achieve a more stable electron configuration with a full outer energy level.
The specific number of electrons that an atom gains or loses in a chemical reaction is determined by its position on the periodic table. Elements in the same group (vertical column) tend to have the same number of valence electrons, which are the electrons in the outermost energy level, and therefore they tend to undergo similar chemical reactions.
For example, alkali metals in Group 1 always lose one electron, alkaline earth metals in Group 2 always lose two electrons, and halogens in Group 7 always gain one electron.
In general, the number of electrons gained or lost in a chemical reaction is determined by the electronegativity difference between the atoms involved. The greater the electronegativity difference, the more likely it is that the reaction will result in the formation of ions.