Interstellar medium
In astronomy, the interstellar medium (or ISM) is the gas and dust that pervade interstellar space: the matter that exists between the stars within a galaxy. It fills interstellar space and blends smoothly into the surrounding intergalactic medium. The energy, in the form of electromagnetic radiation, that occupies the same volume is the interstellar radiation field.
The interstellar medium consists of an extremely dilute (by terrestrial standards) mixture of ions, atoms, molecules, larger dust grains, cosmic rays, and (galactic) magnetic fields (Spitzer 1978). The matter consists of about 99% gas and 1% dust by mass. Densities range from a few thousand to a few hundred million particles per cubic meter with an average value in the Milky Way Galaxy of a million particles per cubic meter.  As a result of primordial nucleosynthesis, the gas is roughly 90% hydrogen and 10% helium by number of nuclei, with additional heavier elements ("metals" in astronomical parlance) present in trace amounts.
The ISM plays a crucial role in astrophysics precisely because of its intermediate role between stellar and galactic scales. Stars form within the densest regions of the ISM, molecular clouds, and replenish the ISM with matter and energy through planetary nebulae, stellar winds, and supernovae. This interplay between stars and the ISM helps determine the rate at which a galaxy depletes its gaseous content, and therefore its lifespan of active star formation.

# The history of knowledge of interstellar space
The nature of the interstellar medium has received the attention of astronomers and scientists over the centuries. However, they first had to acknowledge the basic concept of "interstellar" space. The term appears to have been first used in print by Template:Harvtxt: "The Interstellar Skie.. hath .. so much Affinity with the Starre, that there is a Rotation of that, as well as of the Starre." Later, natural philosopher Template:Harvard citations discussed "The inter-stellar part of heaven, which several of the modern Epicureans would have to be empty."
Before modern electromagnetic theory early physicists postulated that an invisible luminiferous aether existed as a medium to carry lightwaves. It was assumed that this aether extended into interstellar space, as Template:Harvtxt wrote, "this efflux occasions a thrill, or vibratory motion, in the ether which fills the interstellar spaces."
The advent of deep photographic imaging allowed Edward Barnard to produce the first images of dark nebulae silhouetted against the background star field of the galaxy while the first actual detection of cold diffuse matter in interstellar space was made by Johannes Hartmann in 1904 through the use of absorption line spectroscopy. In this historic study of the spectrum and orbit of Delta Orionis, Hartmann observed the light coming from this star and realized that some of this light was being absorbed before it reached the Earth. Hartmann reported that absorption from the "K" line of calcium appeared "extraordinarily weak, but almost perfectly sharp" and also reported the "quite surprising result that the calcium line at 393.4 nanometres does not share in the periodic displacements of the lines caused by the orbital motion of the spectroscopic binary star". The stationary nature of the line led Hartmann to conclude that the gas responsible for the absorption was not present in the atmosphere of Delta Orionis, but was instead located within an isolated cloud of matter residing somewhere along the line-of-sight to this star. This discovery launched the study of the ISM.
Following the identification of interstellar calcium absorption by Hartmann, interstellar sodium was detected by Template:Harvtxt through the observation of stationary absorption from the atom's "D" lines at 589.0 and 589.6 nanometres towards Delta Orionis and Beta Sco.
Subsequent observations of the "H" and "K" lines of calcium by Template:Harvtxt revealed double and asymmetric profiles in the spectra of Epsilon and Zeta Orionis. These were the first steps in the study of the very complex interstellar sightline towards Orion. Asymmetric absorption line profiles are the result of the superposition of multiple absorption lines, each corresponding to the same atomic transition (for example the "K" line of calcium), but occurring in interstellar clouds with different radial velocities. Because each cloud has a different velocity (either towards or away from the observer/Earth) the absorption lines occurring within each cloud is either Blue-shifted or Red-shifted (respectively) from the lines rest wavelength through the Doppler Effect. These observations highlight that matter is not distributed homogeneously and were the first evidence for the presence of multiple discrete clouds within the ISM.
The growing evidence for interstellar material led Template:Harvtxt to comment that "While the interstellar absorbing medium may be simply the ether, yet the character of its selective absorption, as indicated by Kapteyn, is characteristic of a gas, and free gaseous molecules are certainly there, since they are probably constantly being expelled by the Sun and stars."
The same year Victor Hess's discovery of cosmic rays, highly energetic charged particles that rain down on the Earth from space, led others to speculate whether they also pervaded interstellar space. The following year the Norwegian explorer and physicist Kristian Birkeland wrote: "It seems to be a natural consequence of our points of view to assume that the whole of space is filled with electrons and flying electric ions of all kinds. We have assumed that each stellar system in evolutions throws off electric corpuscles into space. It does not seem unreasonable therefore to think that the greater part of the material masses in the universe is found, not in the solar  systems or nebulae, but in 'empty' space" Template:Harv.

# Interstellar matter

## The three-phase model
Table 1 shows a breakdown of the properties and origin of the components of the three phases.

## Structures
The ISM is turbulent, and therefore full of structure on all spatial scales.
Stars are born deep inside large complexes of molecular clouds, typically a few parsecs in size. During their lives and deaths, stars interact with the ISM physically.
Stellar winds from young clusters of stars (often with giant or supergiant HII regions surrounding them) and shock waves created by supernovae inject enormous amounts of energy into their surroundings, which leads to hypersonic turbulence. The resultant structures  of varying sizes  can be observed, such as bubbles and superbubbles of hot gas seen by X-ray satellite telescopes or turbulent flows observed in radio telescope maps.
The Sun is currently traveling through the Local Interstellar Cloud, a denser region in the low-density Local Bubble.

## Interaction with interplanetary medium
The interstellar medium begins where the interplanetary medium of the Solar System ends. The solar wind slows to subsonic velocities at the termination shock, 90100 astronomical units from the Sun. In the region beyond the termination shock, called the heliosheath, interstellar matter interacts with the solar wind. Voyager 1, the furthest human-made object from the Earth, crossed the termination shock on 2004-12-16 and may eventually enter interstellar space, providing the first direct probe of conditions in the ISM Template:Harvard citation.

## Interstellar extinction
The ISM is also responsible for extinction and reddening, the decreasing light intensity and shift in the dominant observable wavelengths of light from a star. These effects are caused by scattering and absorption of photons and allows the ISM to be observed with the naked eye in a dark sky.  The rifts that can be seen in the band of the Milky Way are caused by absorption of background starlight from the uniform disk of stars by molecular clouds within a few thousand light years.
Far ultraviolet light is absorbed effectively by the neutral components of the ISM. For example, a typical absorption wavelength of atomic hydrogen lies at about 121.5 nanometers, the Lyman-alpha transition. Therefore, it is nearly impossible to see light emitted at that wavelength from a star farther than a few hundred light years from Earth, because most of it is absorbed during the trip to Earth by intervening neutral hydrogen.

# Heating of the interstellar medium
The ISM is usually far out of thermodynamic equilibrium. Collisions establish a Maxwell-Boltzmann distribution of velocities, and the 'temperature' normally used to describe interstellar gas is the 'kinetic temperature', which describes the temperature at which the particles would have the observed Maxwell-Boltzman velocity distribution in thermodynamic equilibrium. However, the interstellar radiation field is typically much weaker than in thermodynamic equilibrium; it is most often roughly that of an A star (surface temperature of ~10,000 K) highly diluted. Therefore, bound levels within an atom or molecule in the ISM are rarely populated according to the Boltzmann formula (Spitzer 1978 S. 2.4).

## Heating by low-energy cosmic rays
The first mechanism proposed for heating the ISM was heating by low energy cosmic rays. Cosmic rays transfer energy to gas (through both ionization and excitation) and to free electrons through Coulomb interactions. Low energy cosmic rays (a few MeV) are more important because they are far more numerous than high-energy cosmic rays. Cosmic rays are an efficient heating source able to penetrate in the depths of molecular clouds.

## Photoelectric heating in grains
The ultraviolet radiation emitted by hot stars can remove electrons from dust grains. The photon hits the dust grain and some of its energy is used in overcoming the potential energy barrier (due to the possible positive charge of the grain) to remove the electron from the grain. The remainder of the photon's energy heats the grain and gives the ejected electron kinetic energy. Since the size distribution of dust grains is:
n(r) \propto r^{-3.5}
where r is the size of the dust particle, the grain area distribution is:
r^2 n \propto r^{-1.5}
This indicates that the smallest dust grains dominate this method of heating.

## Photoionization
When an electron is freed from an atom (typically from absorption of a UV photon) it carries kinetic energy away of the order: E_{photon} - E_{ionization}. This heating mechanism dominates in HII regions, but is negligible in the diffuse ISM due to the relative lack of neutral carbon atoms.

## X-ray heating
X-rays remove electrons from atoms and ions, and those photoelectrons can provoke secondary ionizations. As the intensity is often low, this heating is only efficient in warm, less dense atomic medium (as the column density is small). For example in molecular clouds only hard x-rays can penetrate and x-ray heating can be ignored. This is assuming the region is not near an x-ray source such as a supernova remnant.

## Chemical heating
Molecular hydrogen (H_2) can be formed on the surface of dust grains when 2 H atoms (which can travel over the grain) meet. This process yields 4.48 eV of energy distributed over the rotational and vibrational modes, kinetic energy of the H_2 molecule, as well as heating the dust grain. This kinetic energy, as well as the energy transferred from de-excitation of the hydrogen molecule through collisions heats the gas.

## Grain-gas heating
Collisions at high densities between gas atoms and molecules with dust grains can transfer thermal energy. This is not important in HII regions because UV radiation is more important. It is also not important in diffuse ionized medium due to the low density. In the neutral diffuse medium grains are always colder, but do not effectively cool the gas due to the low densities.
Grain heating by thermal exchange is very important in supernova remnant where densities and temperatures are very high.
Gas heating via grain-gas collisions is dominant deep in giant molecular clouds (especially at high densities). Far infrared radiation penetrates deeply due to the low optical depth. Dust grains are heated via this radiation and can transfer thermal energy during collisions with the gas. A measure of efficiency in the heating is given by the accommodation coefficient:
\alpha = \frac{T_2 - T}{T_d - T}
where T is the gas temperature, T_d the dust temperature, and T_2 the post-collision temperature of the gas atom/molecule. This coefficient was measure by Burke & Hollenbach (1983) as \alpha = 0.35.

## Other heating mechanisms
A variety of macroscopic heating mechanisms are present including:
- Gravitational collapse of a cloud
- Supernova explosions
- Stellar winds
- Expansion of H II regions
- Magnetohydrodynamic waves created by supernova remnants

# Cooling of the interstellar medium

## Fine structure cooling
This process is dominant in most regions of the ISM, except regions of hot gas and regions deep in molecular clouds. This occurs most efficiently with abundant atoms having fine structure levels close to the fundamental level such as: CII and OI in the neutral medium and OII, OIII, NII, NIII, NeII and NeIII in HII regions. Collisions will excite these atoms to upper levels, which will eventually de-excite through photon emission, which will carry the energy out of the region.

## Cooling by permitted lines
At higher temperature more levels than fine structure levels can be populated via collisions. For example collisional excitation of the n=2 level of hydrogen will release a Ly\alpha photon upon de-excitation. In molecular clouds excitation of rotational lines of CO is important.