Let's take sodium #Na# that has one electron in its outer shell. Losing it, would mean that it would have the 'sacred' inert-gas configuration (full outer shell, just like Neon).
Now we have fluorine #F#. It has 7 electrons in its outer shell. If it could have just one more, it would also reach the Neon-status.
They clinch the deal, but now #Na# has become #Na^+# (it's positively charged, because there is one electron short for compensating the charge of the nucleus).
And #F# becomes #F^-# for having one too many.
These charged atoms are called ions .
And since opposites attract, #Na^+# and #F^-# tend to stick together, in what we call an ionic bond. And a salt (sodium fluride) has formed.