When atoms form ions, they try to fill up or empty their outer electron shell. In ionic bonding, a metal atom transfers electrons to a non-metal atom, allowing both of them (the metal and non-metal) to have a full outer electron shell.
Group 1 metals
Group 1 metals always lose 1 electron to form positive ions with a charge of +1.
E.g. a sodium atom (Na), with the electronic structure (2,8,1), loses its outer electron when forming an ion to make Na+.
Group 2 metals
Group 2 metals always lose 2 electrons to form doubly positive ions.
E.g. a magnesium atom (Mg), with the electronic structure (2,8,2), loses both its outer electrons when forming an ion to make Mg2+.
Non-metals (groups 6 & 7)
Non-metal atoms always gain electrons to form (become) negative ions.
E.g. a fluorine atom (F), with the electronic structure (2,7), will gain an electron when forming an ion to make F-.
Noble gases (Group 0)
Noble gases already have a full outer shell. Noble gases are unreactive and don't normally form ionic bonds with other elements.