Electrons generally want to be as close to the
nucleus as possible because of electromagnetic
attraction (positive <---> negative).
It turns out that electrons fill in, from
inside to the outside, in discrete levels.
Bettelheim et al.
Electrons essentially
reside only at these discrete distances
(energies, really).