As we learned in the "What" section, the interstellar medium is the material between the stars. How and when did this material get there? To find this out, we need to learn a little bit about the history of the Universe. Learning about the history of the Universe is difficult for humanity. There are many reasons for this, but here are two of the most important:
Astronomers and most other scientists believe that an event known as the "Big Bang" occurred some 15-20 billion years ago. According to this theory, the Universe started with a single event, and space itself has been expanding ever since. The primordial matter produced in the Big Bang was almost entirely hydrogen and helium (with trace amounts of lithium, beryllium, and boron) -- there were no heavier elements. Most of the interstellar medium today is still made up of these light elements, but there are other heavy elements as well, especially in the dust. Where did these elements come from?
The first stars that formed (in the Universe and our galaxy), were made only of these light elements. These stars were very massive, and had very short life spans compared to many of the stars today. These stars continually fused the atoms of the lighter elements together to create the heavier elements of carbon, nitrogen, oxygen, and the rest of the elements up to iron. Then, when these stars died in their explosive end (a supernova), the elements heavier than iron were formed, from cobalt to uranium. The supernova explosion caused all of the elements of the star to be hurled into space, mixing with and contaminating the primeval interstellar gas. The interstellar medium was now enriched with the elements needed to form new stars and planets and even life.