This is due to the atom's atomization energy, which is the amount of energy needed to release an electron from its atom, or 1 mole of electrons from 1 mole of atoms.
When an electron is "lost" from an atom it does not necessarily go to another atom. It can instead become "free". (You can think of a free electron as able to move around between atoms without belonging to any specific one - this is the case of electrons in metals, but that's another topic).
What determines that an electron has left an atom is its distance from the nucleus: it has to go beyond a certain distance depending on various aspects of the atom, including weight, charge, no. of electrons, etc.
( To explain in more depth: the electron energy levels surrounding the atom's nucleus actually converge as they become farther from the nucleus, until a specific point that can be considered the "end" of the atom - it no longer has any hold on electrons beyond that.)
The way that an electron "leaves" and atom in this way is basically due to a gain in energy. When an electron has more energy it can move further away from the nucleus, until eventually it's become far enough to be considered free.
The amount of energy needed for this to occur has been found for most atoms and is called the ionization energy.