As you may have learned by now, the interstellar medium contains particles that have origins in many different events. The majority of the interstellar gas and dust that we see was produced by star death. We do not ordinarily think of stars as transient objects -- after all, the constellations do not change perceptibly in our lifetimes, and stellar events on a scale that we can see are rather rare -- but even stars are born, and must also eventually die.
Stars produce energy by the process of fusion -- two or more atoms, like hydrogen or helium, are combined under intense pressure and temperature to produce a heavier atom. This releases a fantastic amount of energy, which then allows the reaction to continue elsewhere in the star. (Humanity has harnessed this process to a degree in its nuclear weapons: the bombs that were used in World War II were fission bombs, which split atoms, and although they produce much energy -- hense much devastation -- this energy pales in comparison to the power of fusion bombs. A fusion reaction, while relatively easy to start, is not at all easy to control, which is one of the reasons fusion has not yet been exploited as an energy source, the way fission has.)
When a star has fused all of its hydrogen into helium, it begins fusing the helium into lithium, and so on up the periodic table. If a star is massive enough, it will produce elements all the way up to iron. Each time the star begins fusing a new element, the delicate balance between its gravitational pull and the pressure inside it also undergoes a change, and so the star may grow or shrink. In many of these changes, the star throws off a layer of matter at very high velocities, as in the example at right. These expanding shells of matter surround some of the stars we see from Earth. The most dramatic star deaths -- novae and supernovae -- are created by super-massive stars, when the force of gravity is no longer enough to keep the star from expanding. These stars explode in a tremendous release of energy, and matter is thrown off at incredible speeds and very high temperatures (in fact, most of the radiation occurs in x-ray frequencies). When this matter encounters patches of interstellar gas, it excites and ionizes them, producing an emission nebula.
Interstellar material also comes from stars which are still undergoing stable fusion reactions. Our own sun sends out streams of particles and radiation -- the solar wind -- that interact with particles flowing into our solar system. Given that all stable stars also produce a similar "wind", a substantial portion of the interstellar medium can be accounted for in this way.
Clouds of interstellar dust have accreted (clumped together) over millions of years. This dust is a varied mix of compounds and elements; some interstellar clouds even contain organic molecules like acetylene and acetaldehyde, known precursors of amino acids. The atoms needed to create these clouds of molecules have generally come from past supernovae.
What does the future hold for large clouds of interstellar gas and dust? Many of the denser clouds become stellar nurseries: the image at right is of a stellar nursery in a neighboring galaxy (NGC 604, which lies in the neighboring spiral galaxy M33, located 2.7 million light-years away in the constellation Triangulum). (Our own solar system was probably born in this way; and we are all made of stardust.) Eventually, these stars will also die, some more spectacularly than others, and begin the cycle again. Only when matter in the expanding universe becomes too sparse for gravity to pull it together will this process end.