In the process of analysing stars, one important factor is their composition. It is impractical and some could argue impossible with modern technology to gather a representative sample of a star in order to determine which elements are present. Even if it was possible to execute this task, one could not be certain that the sample obtained would be representative of the entire star; not to mention every star in existence. One process of determining the composition of a star is through spectroscopy, which is defined in Encyclopedia Britannica as the “study of the emission and absorption of light and other radiation by matter, as related to the dependence of these processes on the wavelength of the radiation” . The processes of emission and absorption occur at the atomic level as a result of radiation being expelled or entering the atom and primarily involves the electrons present in a given atom.
Every atom contains a number of electrons (negatively charged particles) corresponding to its atomic number on the periodic table (if it is neutral) and energy levels where the electrons reside. For an atom with a charge (referred to as an ion), its number of electrons is indicated by its atomic number and net charge such that a charge of -x indicates the addition of x electrons and +x indicates the removal of x electrons with respect to the atom’s atomic number. A visual representation of the energy levels of an atom (denoted by the quantum number ‘n’ which indicates which level is being considered) is shown below as Figure 1. One may note that Figure 1 is representative of the Bohr model which depicts the energy levels as circles of increasing radius surrounding the nucleus (containing protons with positive charge and neutrons of no charge). This model does not accurately show the shapes of the orbitals, but is included for clarity on the concept of energy levels.
Figure 1: The First Four Energy Levels of an Atom (n=1, 2, 3, 4)
When the atom absorbs a photon (radiation of a certain energy), one of these electrons can be promoted or move up in energy levels depending on how much energy was absorbed. Since the levels are discrete, a certain amount of energy is required to promote an electron from one energy level to another. The electron will eventually move back down to its previous state, emitting a photon (radiation of a certain energy). The Electromagnetic Spectrum is a spectrum of all radiation according to wavelength (representing relative length of the radiative wave) shown as Figure 2 below.
Figure 2: The Electromagnetic Spectrum According to Wavelength
When a spectrum is taken of a given body (atoms, stars, etc), there are spectral “lines” referred to as emission or absorption lines (depending on whether the spectrum is emission or absorption) that occur when an electron moves down or up in energy levels respectively (when emitting or absorbing a photon). Since each atom has a specific amount of electrons, energy levels, and corresponding electronic transitions, the measurement of a star’s spectrum can be used to analyse the star’s composition by relating the wavelength of the radiation to its energy using Equation 1 below where ‘E’ represents the energy of the radiation, ‘h’ is Planck’s constant, ‘c’ is the speed of light in metres per second, and ‘λ’ is the wavelength of the photon (radiation). Since ‘h’ and ‘c’ are constants, wavelength is the only variable that needs to be determined in order to determine the energy of the photon. It is worth noting that energy is inversely proportional to wavelength which indicates that a higher energy photon corresponds to lower wavelength (and vice versa).
Figure 2 below shows the (absorption) spectrum of a star with absorption lines from certain electronic transitions (denoted as Hα, Hβ, Hγ, and Hδ) above a plot of wavelength vs intensity. These two plots demonstrate the same information, but the spectrum itself is what would be obtained directly from a spectrometer whereas the intensity vs wavelength plot would be generated from the spectrometer data after it was obtained for analysation.
Figure 3: Absorption Spectrum and Corresponding Intensity vs Wavelength Plot from 
The year 1925 marks the first successful prediction of composition of stars through their spectra while also predicting a given star’s temperature and density. This prediction led to the assumption that stars are primarily composed of hydrogen and helium. In 1938, it was discovered that the energy of stars comes from the fusion of protons which allows for heavier elements to be generated (since the amount of protons in an atom is equal to the atomic number, and thus by fusing or combining protons the atomic number and corresponding identity of an atom will change).
Figure 4: Example Star Absorption Spectrum vs Elements Present
In Figure 3, an example absorption spectrum is shown assuming that a given star only contains Hydrogen, Helium, and Sulfur (with their respective emission spectra shown above the star’s absorption spectrum for reference). Since in reality stars have an abundance of elements and corresponding spectral lines (as shown in Figure 2), the analysation required for determination of composition is much more complex than what is shown in Figure 3. Nevertheless, it is an adequate visual representation of the process required to determine the composition of a star (or another astronomical body) from its spectrum.
 Encyclopedia Britannica. “Stellar spectra.” Encyclopedia Britannica. https://www.britannica.com/science/star-astronomy/Stellar-spectra.
 Encyclopedia Britannica. “Evolution of stars and formation of chemical elements.” Encyclopedia Britannica. https://www.britannica.com/science/physical-science/Evolution-of-stars-and-formation-of-chemical-elements.
 Encyclopedia Britannica. “Spectroscopy.” Encyclopedia Britannica. https://www.britannica.com/science/spectroscopy.
 (Figure 3) https://casswww.ucsd.edu/archive/public/tutorial/Stars.html
 (Featured Image) https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.istockphoto.com%2Fphotos%2Fmilky-way&psig=AOvVaw0neoBxmTLnMwwcFs3EeZ3T&ust=1651660667444000&source=images&cd=vfe&ved=0CAwQjRxqFwoTCNjuvtORw_cCFQAAAAAdAAAAABBP
 (Figure 1) https://sites.ualberta.ca/~pogosyan/teaching/ASTRO_122/lect5/lecture5.html
 (Figure 4) https://starmappers.wordpress.com/2017/03/30/spectral-lines-and-very-fancy-graphics/
 (Figure 2) https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.science-sparks.com%2Fwhat-is-the-electromagnetic-spectrum%2F&psig=AOvVaw2CMBaBStLBaUTQiEXF7qIF&ust=1651661404006000&source=images&cd=vfe&ved=0CAwQjRxqFwoTCJDR96-Uw_cCFQAAAAAdAAAAABAD