explanation:
metals have excess of electrons whereas non-metals have deficiency of electrons. thus, in order to gain stability metals easily donate their electrons to the non-metals.
for example, electronic configuration of sodium is and electronic configuration of phosphorous is .
when a phosphorous atom and sodium atom combine together then sodium will donate is extra one electron to the phosphorous atom. as a result there will be formation of ionic bond between sodium and phosphorous.
the reaction will be as follows.
there, are three sodium sodium atoms and each of them will donate its one extra electron to phosphorous atom. thus, the sub-shell of phosphorous gets completely filled.
thus, we can conclude that electrons are transferred from atoms of sodium to atoms of phosphorous. this transfer makes the sodium atoms donate one electron and the phosphorous atoms to gain one electron. as a result, the sodium and phosphorus atoms strongly attract each other.