When the atoms of a gas or vapor are excited, for instance by heating or by applying an electrical field, their electrons are able to move from their ground state to higher energy levels. As they return to their ground state, following clearly defined paths according to quantum probabilities, they emit photons of very specific energy. This energy corresponds to particular wavelengths of light, and so produces particular colors of light.