When we add extra energy to the particles of a substance (to the atoms, the ions, the molecules), for example by heating or by radiation, then this substance can take up some of that energy.
Question is: where has this energy gone? (because: energy never gets lost, isn't it?)
That caught energy can be stored in different ways in such a particle:
  1. the energy is taken by the electrons of a certain atom.
    The more energty electrons have, the more 'independent' they are;
    in other words:
    the further electrons are from the nucleus, the more 'independent' they are, and the more energty they possess.
    So, if that added (sufficient) energy arrives at the electrons, those electrons must dislocate to a level further from the nucleus (see B).
    It can even happen that such an electron receives so much energy, that it will leave the atom; a positive ion is formed (see A).
    1. one or more electrons absorb so much energy that they remove themselves completely from the atom; this is called ionisation and does not deliver any spectrum.
    2. One electron absorbs energy and moves to a more outside level, electron shell. The energy still is in the atom, with the consequence that this atom is no longer stable. The more energy a particle has, the more unstable it is.
      This unstable particle is now in a EXITED STATE.
      Electrons with too much energy will very soon (within fractions of seconds) fall back into their original situation, restore the original more stable GROUND STATE.
      This process of falling back can occur directly, but also via various 'in between states'. Every step back can find another sublevel to stay for a moment. But note: every step backwards means that the electron must lose some energy. This loss of energy often is realised in the form of electromagnetic radiation with a certain wave length.
      The way that electrons chose to fall back is different per atom (in Na-atoms different from Ca-atoms). So is also the emitted radiation different per element/atom.
      We can analyse that emitted radiation and measure it; sometimes even with bare eye when the wave length of the radiation is between 400 and 700 nm.

  2. The energy is absorbed by molecules.
    Within molecules, the atoms have some movement relative to each other. They can vibrate, every molecule, every atom in its own way. If added energy is not enough to exite electrons, to send them to a more outer shell or even outside the atom, then there is another option.
    Molecules can be treated with infrared light. If the molecule can absorb the energy (or part of it) of that radiation, it will increase the vibration, or it wil change orientation of the vibration, causing thus a kind of exited state. This, again, is not stable. The exited molecule will fall back to the original ground state, emitting some new radiation. This new radiation can be measured with a spectrometer and conclusions can be drawn about the character of the molecules.

  3. The energy is absorbed by the atom NUCLEUS.
    Yes, also the nucleus of an atom can absorb certain energy and let it go thereafter. And again, this delivers a spectrum that can be detected. The magnetic field is here very important, connected to the orientation of particles.

We can distinguish two kinds of spectra:
  1. The absorption spectrum
  2. The emission spectrum
Light with a certain (variable) wave lenght is sent through the investigated substance. At some wave lenghts, the substance will absorb part of the light. The consequence will be that the outcoming light is poorer in radiation of the light with that particula wave lenght(s).
A detector will notice that and op the plotter (grafic) can be seen a peek going down in the grafic.

The exited molecules are not stable and will (fast) fall back in the basic situation, the ground stand. During that back fall, new radiation is emitted (in all directions). Also this emission radiation can be detected (in the drawing with an angle of 90 degrees) and put in a grafic. You can see peeks up.

The pattern of a spectrum often shows what molecule is involved. They are kind of finger print of the molecules and atoms.