The Birth of Cosmology
From 1912 to 1914, Vesto Slipher measured spectra of the class of objects known as spiral nebulae while working at the Lowell Observatory in Flagstaff, Arizona. To his surprise he discovered that of 14 nebulae analyzed, 12 exhibited spectra shifted towards the red end of the spectrum. This information provided further evidence that the spiral nebulae were not objects associated with our Milky Way, but were in fact separate galaxies external to our own. The debate regarding the nature of nebulae arose in part from the confusion due to scant spectroscopic observation of "spiral" and "diffuse" nebulae The earliest spectra of diffuse nebula showed emission lines indicating their they were composed of hot, thin gases while spiral nebulae had absorption lines in their spectra, indicating they were composed of stars (the overwhelming majority of stars exhibit absorption spectra from their relatively cool lower atmospheres).
Einstein's Cosmos
When Einstein published the field equations of General Relativity in 1915, he sought to describe the shape of spacetime in the presence of matter. To do this he had to express the results using tensors (similar to matrices, they can be summed over any number of dimensions). Typically, the notation uses indices μ summed over the spatial dimensions (x,y,z) and ν summed over (x,y,z) and can is expressed as

Some terms may be familiar, such a Newton's constant of universal gravitation G, but the others may require a bit of explanation. The are:
gμ&nu = the Riemann tensor describing the scale factor (metric) of spacetime. This is essentially a determination of the distance between adjacent points in spacetime.
Rμ&nu = the Ricci tensor, and is essentially derivatives of the Riemann tensor.
R = the "trace" of the Ricci tensor describing the radius of spacetime's curvature
Tμ&nu = the stress-energy tensor describing the density of mass-energy in spacetime
So, with all of these complex and confusing factors and notation, Einstein believed that it was possible to construct a model universe by inserting values into the tensors. Because he and his contemporaries were still firmly rooted in the Newtonian concept of a universe that was infinite in both size and age, the only reasonable solution envisioned was a matter-filled universe that was static.
Unfortunately for him, the calculations inescapably lead to model universes that either collapsed in on themselves or expanded. A static solution could not be found. Since the best known data of the time—measurements of the proper motion of stars—indicated very small spatial velocities, Einstein reasoned the universe had to be static and thus, he inserted a braking term in 1917: the infamous cosmological constant Λ. He inserted the constant as a multiplicative term on the Riemann tensor. The sign of the term could be changed to halt either expansion or collapse depending on the situation.
In Einstein's own words,
"In order to arrive at this consistent view, we admittedly had to introduce an extension of the field equations of gravitation which is not justified by our actual knowledge of gravitation...The term is necessary only for the purpose of making possible a quasi-static distribution of matter, as required by the fact of the small velocities of the stars."
Either he was unaware of Slipher's measured recession velocities of a few years earlier or believed the small sample size was insufficient to demonstrate an expanding universe. Only after being told of Hubble's observations and calculation that implied an expanding universe did Einstein conclude that the cosmological constant was unnecessary. A quasi-static universe simply did not match the collected data.
Determining the Distance to the Great Spiral
in Andromeda
The debate over the nature of the spiral nebulaa debate that was argued
to a draw in the Curtis-Shapley debatewas settled once and for all
by Edwin Hubble in 1923 when he succeeded in identifying examples of Cepheid
variable stars in the spiral nebula M31 and calculated the great spiral
nebula's distance to be over 1 million light-years.

Cepheid variables are unstable yellow giant stars that expand and contract over regular time intervals (see the light curve of Delta Cephei below) as they fuse helium into carbon in their cores.
Henrietta Leavitt had recently discovered a relationship between the average total energy output (luminosity) of Cepheids and the period of variability. The greater the luminosity, the longer the period. This is the period-luminosity relationship (shown below) with the luminosity converted to absolute magnitude. The absolute magnitude M is the hypothetical brightness of an object if we imagine its distance is 10 parsecs (32.6 light-years).

Absolute magnitude is useful to astronomers because it removes an object's actual distance from consideration and thus, allows a direct comparison between the energy output of objects. Since a distant luminous object can appear fainter than a nearby dim object, absolute magnitude gives a means for astronomers to directly compare the difference in energy outputs.
Hubble used the 100-inch reflector on Mount Wilson to photograph individual Cepheid variables in the Andromeda spiral. Using Leavitt's period-luminosity relationship, he was able to estimate the absolute magnitude of the Cepheids in M31 from the period of variability he observed in his photographs. It was then a simple procedure to calculate M31's distance using a formula called the distance modulus. This equation uses the difference between an object's absolute magnitude and its observed, or apparent, magnitude as seen from Earth. The equation is
M = m + 5 - 5logd
where M is the estimated absolute magnitude, m is the magnitude as observed from Earth, and d is the distance in parsecs.
Using this formula, Hubble found that the calculated distance to the Great Spiral was nearly 1 million light-years—far beyond any reasonable estimate of the Milky Way's size. While this distance was enormous (the Milky Way's diameter was estimated to be nearly 300,000 light-years), later measurements and refinement of the period-luminosity relationship for Cepheids increased the distance measurement to M31 to over 2 million light-years. Also, the discovery of dust in the interstellar medium decreased the estimated size of our Milky Way to 100,000 light-years.