A typical star begins as a thin cloud of hydrogen gas that, under the force of gravity, collects into a huge, dense sphere. When the new star reaches a certain size, a process called nuclear fusion ignites, generating the star's vast energy. The fusion process forces hydrogen atoms together, transforming them into heavier elements such as helium, carbon and oxygen. When the star dies after millions or billions of years, it may release heavier elements such as gold.
TL;DR (Too Long; Didn't Read)
Nuclear fusion, the process that powers every star, creates many of the elements that make up our universe.
Nuclear Fusion: The Big Squeeze
Nuclear fusion is the process during which atomic nuclei are forced together under tremendous heat and pressure to create heavier nuclei. Because these nuclei all carry a positive electric charge, and like charges repel each other, fusion can happen only when these enormous forces are present. The temperature at the sun's core, for example, is about 15 million degrees Celsius (27 million degrees Fahrenheit), and has a pressure 250 billion times greater than earth's atmosphere. The process releases huge amounts of energy -- ten times that of of nuclear fission, and ten million times as much as chemical reactions.
Evolution of a Star
At some point, a star will have used up all the hydrogen in its core, all of it having been turned to helium. At this stage, the outer layers of the star will expand to form what's known as a red giant. Hydrogen fusion is now concentrated on the shell layer around the core and, later on, helium fusion will occur as the star starts to shrink again and becomes hotter. Carbon is the result of nuclear fusion among three helium atoms. When a fourth helium atom joins the mix, the reaction produces oxygen.
Only the bigger stars can produce heavier elements. This is because these stars can pull up their temperatures higher than the smaller stars like our Sun can. After hydrogen is used up in these stars, they go through a series of nuclear burning depending on the types of elements produced, for example, neon burning, carbon burning, oxygen burning or silicon burning. In carbon burning, the element goes through nuclear fusion to yield neon, sodium, oxygen and magnesium.
When neon burns, it fuses and produces magnesium and oxygen. Oxygen, in turn, yields silicon and the other elements found in between sulfur and magnesium in the periodic table. These elements, in turn, produce the ones that are near iron on the periodic table -- cobalt, manganese and ruthenium. Iron and other lighter elements are then produced through continuous fusion reactions by the above-mentioned elements. Radioactive decay of unstable isotopes also occurs. Once iron is formed, nuclear fusion in the star’s core comes to a stop.
Going out with a Bang
Stars a few times bigger than our sun explode when they run out of energy at the end of their lifetimes. The energies released in this fleeting moment dwarf that of the star's entire lifetime. These explosions have the energy to create elements heavier than iron, including uranium, lead and platinum.