# Why are electrons transferred in an ionic bond?

I've been taught at school that in an ionic compound like $\ce{NaCl}$, electrons are transferred from the $\ce{Na}$ to the $\ce{Cl}$ to form $\ce{Na+}$ and $\ce{Cl-}$ which both have full outer shells. But what causes these electrons to be transferred?