How are ions formed?

The gain or loss of electrons gives ions.