The internal structure of an atom (in terms of its protons and neutrons) will create regions which are called orbitals. We commonly think of atoms according to the Bohr model, where electrons orbit the nucleus like little planets. This model is wrong. the truth is that we can only determine the location of an electron based on a statistical model, and that gives us regions where electrons are more likely or less likely to be found if we searched for them there. These areas where electrons are most likely to be found are called orbitals.
The orbitals differ in energy states. An electron in a high orbital needs high energy, and electrons with less energy will be at lower orbitals. When the number of electrons and protons are equal (ie the atom is not an ion) and the electrons occupy all of the lowest energy orbitals possible, that is called the ground state.
if an electron at the ground state gets extra energy, it can jump to a higher orbital. However, the various orbitals require certain, specific amounts of energy, and the energy gaps between the orbitals are specific amounts of energy, based on the orbital structure dictated by the nucleus (the details of all of this require some of the ugliest differential equations and eigenfunctions you're likely to ever see). So the energy absorbed by an electron to jump from a low orbital to a high orbital must be of a specific amount. After time, the electron will eventually relax back to the lower orbital. When it does, it will release its excess energy in the form of a photon with the precise amount of energy that separates the two orbitals.
For a given atom, there is a certain number of specific orbital transitions possible, and each possible transition will correspond to a single band on the spectrum produced by the pure element when heated to. So while a given atom can give several colors, the number of colors it can give are limited.