Scientists have had the technology to observe discrete spectra since the beginning of the 19th century. They had to wait over a hundred years, though, for an explanation of how the discrete spectra were produced. They knew that it was produced by atoms and that atoms had negative and positive charges in them. Some models of the atom were similar to our current one: the positive charges are concentrated in a central nucleus with the negative charges swarming around it, but the atoms should be unstable. As the negative charges (called electrons) move around the nucleus, they should radiate light and spiral into the nucleus in about 10-16 second. This is obviously contradicted by common experience!
Niels Bohr (lived 1885--1962) provided the explanation in the early 20th century. He said that the electron can be only found in energy orbits of a certain size and as long as the electron is in one of those special orbits, it would radiate no energy. If the electron changed orbits, it would radiate or absorb energy. This model sounds outlandish, but numerous experiments have shown it to be true.
In Bohr's model of the atom, the massive but small positively-charged protons and massive but small neutral neutrons are found in the tiny nucleus. The small, light negatively-charged electrons move around the nucleus in certain specific orbits (energies). In a neutral atom the number of electrons = the number of protons. The arrangement of an atoms's energy orbits depends on the number of protons and neutrons in the nucleus and the number of electrons orbiting the nucleus. Because every type of atoms has a unique arrangement of the energy orbits, they produce a unique pattern of absorption or emission lines.