What is spectroscopy?
Okay, scientists love classifying things into types, because it makes describing their properties a bit easier. We start with generic broad categories that define general properties and then go to sub categories or exceptions as we discover other specific properties, so let’s start based on a very generic and broad classification of every object in the universe based on ‘light’
So, there are two types of objects:
Non luminous objects – objects which do not generate any light of their own but are visible to us because of the light they reflect like the moon, the earth, all the other planets, asteroids, me, you, the pencil, the eraser etc.
Luminous – objects which generate their own light like the sun, candle, bulb
These are the objects which undergo exothermic reactions (could be combustion, other chemical reactions, nuclear reactions, kinetic or vibrational energy of particles that gets out as heat) but in essence undergo some sort of process that makes them eject photons and hence emit electromagnetic radiations, a part of which ‘could’ fall in the visible spectrum that we see as light. For more details on electromagnetic radiations and the e/m spectrum, you can refer to an upcoming article on Electromagnetic waves.
Here’s a mice overview of the electromagnetic spectrum and its scale:

https://commons.wikimedia.org/wiki/File:EM_Spectrum_Properties_(Amplitude_Corrected,_Bitmap).png#file
Now these luminous objects undergo something that makes them emit these radiations, studying these radiations that we receive we can reverse engineer and predict what sort of process they must have undergone to emit that specific radiation.
This is how we know what stars are made of, what reaction they are undergoing, what is their age, the temperature, their distance etc. and this study of analyzing the electromagnetic spectrum is called spectroscopy.
(*Note it’s not just luminous objects we can study with what they emit but we can also study non-luminous objects with what they absorb and reflect, which is how we know there are water vapors in the atmosphere of a distant planet! This is discussed later when we describe the types of spectra)
How does it work in principle?
This is discussed in more details, in the article on Light, but just to give a brief overview, the light we receive from sun is polychromatic – i.e. its made up of several different colors, which we can observe when we disperse the light e.g. pass it through a prism.
Now, why is that so, because each color, basically a wave (light can be considered as a quantum packet or a photon with oscillating electric and magnetic fields in perpendicular directions – i.e. an electromagnetic wave) is characterized by a specific wavelength (distance between successive peaks or troughs) or frequency (number of waves in unit time), if you know one of the two, you know the other because speed of light is constant (c = wavelength * frequency ). If you want to learn more about waves refer to the article about Light as a wave.
When we pass this light or any radiation we get through a dispersive medium, in case of visible light its a refractive medium like prism, light follows a very very basic law called fermat’s principle, i.e. it travels along the path that takes the least time (its basically always in a rush!)
And because the medium is changed like a prism is made up of glass, which is more optically dense, and if it is a polychromatic light, each constituent wave carries different energy levels and interacts with the molecules differently, to minimize the time traveled, each wave chooses a different path and hence each color bends differently and the incident light wave disperses into its constituents.
You can think that all the molecules/atoms are more tightly packed and you face more resistance and when you and your friends want to pass through a crowded space at an amusement park you all disperse in the crowd finding a path you can squeeze into based on your size to get to the counter on the other side – you can learn about the actual science in the topic of Refraction which discusses snell’s law and angles of refraction.
For easier understanding we were talking about light waves, this happens with all the electromagnetic radiations that we receive, some of them could be light waves, some not, they might be invisible to the eyes.

https://commons.wikimedia.org/wiki/File:Light_dispersion_conceptual_waves.gif
How does it work in practice?
Spectrometer / spectroscope / spectrograph (..any name that implies spectrum and analysis) is what the instrument used for spectroscopy is called in general.
Here is a simple spectrograph:
https://www.atnf.csiro.au/outreach/education/senior/astrophysics/spectrographs.html
For however cool it is, in design and simplicity, prism is unfortunately not the instrument used inside them. The reason is because this beloved instrument is biased towards shorter wavelengths, that is they provide greater dispersion for shorter wavelengths causing a non linear spectrum. To see the actual math behind it refer to the section of dispersion in the article Refraction
We usually use these things called diffraction gratings which is an optical element – a strip with a large number of thin microscopic slits, for more details on diffraction refer to the article Light as a Wave
Types of spectra
As hinted earlier, it’s not just the luminous objects we can study, the image below gives an idea of different types of spectra

Credit: NASA, ESA, and L. Hustak (STScI).
https://webbtelescope.org/contents/articles/spectroscopy-101–types-of-spectra-and-spectroscopy
Continuous
Well its continuous and has all the colors, what else to say.
The sun, whose warm yellow white daylight we all bathe in, is an example of a blackbody! .. Well almost (a blackbody is an object which absorbs all radiations and will emit all radiations at a certain temperature – read more in the article about Blackbodies)
Blackbodies have a continuous spectra characterized at specific temperatures, this is how looking at the peak of a continuous spectra we can actually say what type of star it is

Credit: NASA, ESA, L. Hustak and A. James (STScI).
https://webbtelescope.org/contents/articles/spectroscopy-101–types-of-spectra-and-spectroscopy
Absorption Spectra
Consists of lots of black lines called absorption lines, each element has specific absorption lines because it absorbs only specific photons corresponding to specific energy levels that the electrons in its orbits require to jump (this is based on the fact that orbits and energies of electrons in specific orbits in an atom in quantized – therefore each element in a way has a fingerprint absorption/emission spectra – for more details on this refer to the articles of Atom and Photoelectric effect)

Credit: NASA, ESA, and L. Hustak (STScI).
https://webbtelescope.org/contents/articles/spectroscopy-101–how-absorption-and-emission-spectra-work
So when you pass some light (continuous spectrum) through a gas – some of it will be absorbed by the atoms of the gas producing black lines in the continuous spectrum – if you observe the same continuous spectrum you notice black lines of the absorption spectrum

Credit: NASA, ESA, and L. Hustak (STScI)
https://webbtelescope.org/contents/articles/spectroscopy-101–types-of-spectra-and-spectroscopy
Emission Spectra
In simple terms is inverse of absorption spectra, going to the same example, when you pass some light (continuous spectrum) through a gas – some of it will be absorbed by the atoms of the gas producing black lines in the continuous spectrum – if you observe the same continuous spectrum you notice black lines of the absorption spectrum.
The excited electrons will jump back to their ground state releasing the same energy they absorbed – causing an emission of radiation of the same wavelength and frequency – if we observe this emitted light (in all directions) – we will notice an emission spectrum, which is sparse. It is also a fingerprint spectra, you can get more details on Balmer and Layman and Paschen lines in another upcoming article.

Credit: NASA, ESA, and L. Hustak (STScI)
https://webbtelescope.org/contents/articles/spectroscopy-101–how-absorption-and-emission-spectra-work
There are other names for specific types of spectra based on the interaction of light with the material, these are called transmission and reflectance spectra.
Transmission spectra is basically another name for specific case of absorption spectra where we study the light transmitted through say a planet’s atmosphere and try to match its fingerprints to specific elements to get the composition of that atmosphere / gas
Reflectance spectra is a mixture of absorption and emission spectra and also depends on the surface of reflection, i don’t know much details about it, so, if you want to know more, there are some resources available online, including this one by Caltech university that discusses Reflectance IR Spectroscopy:
https://mmrc.caltech.edu/FTIR/Literature/Diff%20Refectance/Reflectance%20IR%20Khoshhesab.pdf
References
https://webbtelescope.org/contents/articles/spectroscopy-101–introduction
