An electron in an isolated atom can have only certain fixed energies, called discrete energy levels. It cannot have an energy between two levels. The levels are given negative values because a free electron at rest is taken to have zero energy, and a bound electron has less than that.
When an electron falls to a lower level it emits one photon. The photon energy equals the difference between the two levels. Only certain differences exist, so only certain wavelengths are emitted. This gives an emission line spectrum: bright lines on a dark background.
A cool gas absorbs photons whose energy exactly matches a jump upwards. White light passed through it shows dark lines, an absorption line spectrum.