Nucleosynthesis is the buildup of heavy elements from lighter ones by nuclear fusion. Helium and some lithium was produced by cosmic nucleosynthesis just after the Big Bang, but today most element-building nucleosynthesis takes place in stars.
Stellar nucleosynthesis converts hydrogen into helium, either by the proton-proton chain or by the carbon-nitrogen-oxygen cycle. As a star evolves, a contracting superdense core of helium is produced from the conversion of hydrogen nuclei into helium nuclei. Eventually, the temperature and pressure inside the core become high enough for helium to begin fusing into carbon. If the star has more than about twice the Sun's mass, a sequence of nuclear reactions then produces heavier elements such as oxygen, silicon, magnesium, potassium, and iron. Successively heavier elements, as far as iron (in the most massive stars) are built up in later stages of stellar evolution by the triple-alpha process. The heaviest elements of all are produced by explosive nucleosynthesis in supernova explosions, by mechanisms such as the p-process, r-process, and s-process.