Why do electrons stay in wires?
That’s a question I had never asked myself, and it’s one few people have considered. The answer isn’t as easy or obvious as you’d expect, but if you’re curious about it, read on.
The short answer is that the electron clouds and the nuclei of the atoms at the edge of the metal form a dipole. A dipole is essentially a set of two charges that form a mathematically unique field (see the Wikipedia article for a picture). The field from this dipole keeps the electrons in, as they’d need a kinetic energy of roughly 4 electron volts (eV) to get through the dipole field.
If you’re having trouble imagining it, an analogy is a water channel, where the dipole field is the walls and the electrons are the water. The water doesn’t have enough energy to get over the boundary (this case the potential barrier is gravitational rather than electrical), and so it flows along the path of the channel. The analogy is good for another reason too, water has to flow downhill (following the gravitational field), and so do the electrons (following an electrical field). (One difference is that the gravitational field is created by the Earth, whereas the electric field is created by the current.)
This effect has to do with the work function, the energy needed to pull an electron off of a metal into free space. Experiments around the turn of the century had discovered that when a metal was bombarded with light of the right frequency, electrons would fly off, creating a current. This is called the photoelectric effect. Physicists couldn’t quite explain it until Einstein realized that it meant that light is both a wave, with a frequency and wavelength, and a particle with quantized energy and momentum. One of his 1905 trio of amazing papers put forth this hypothesis, and it’s what won him his Nobel Prize (nope, Relativity never won him one, and the other two were on Brownian Motion and Special Relativity).
So that’s why electrons stay in wires (and metals in general).