Non-metals gain electrons (due to more no. of valence electrons), forming an ion with negative charge as it is easy for them to gain electron and attain stable or octet configuration rather than loosing electrons.
E.g. Chlorine (At no. = 17; electronic config- 1s2, 2s2, 2p6, 3s2, 3p5) non-metal has 7 valence electrons and it is easy for it to gain 1e rather than loosing 7e to attain stable configuration. Hence it gains 1e forming Cl- anion.