Eventually, all stars run out of fuel in their cores. They lose their equilibrium as the force of gravity comes to dominate. Different-mass stars end their lives differently. Low-mass stars die quietly as their nuclear fires dwindle. The core in a Sun-like star collapses rapidly into an Earth-size white dwarf. The star's outer layers, containing atoms formed in the fusion process, are left as expanding bubbles or jets of material that expand out into the universe. A massive star's core collapses almost instantaneously. It rebounds outward and strikes other material falling inward. This collision occurs with so much energy that it creates all of the naturally occurring elements and blows the star apart. This explosion, a supernova, is the source of all the heavy elements that are found in nebulae, stars, planets, and interstellar space.
Deep in cold, interstellar space, elements such as carbon, oxygen, and nitrogen can combine with primordial hydrogen to form complex molecules, particularly in dense condensations of gas called molecular clouds, where collisions between gas atoms and dust grains are possible. A large number of complex molecules, particularly those involving carbon atoms, have been detected in interstellar space.