In astronomy – and astrophysics and cosmology – there are two main kinds of nucleosynthesis, Big Bang nucleosynthesis (BBN), and stellar nucleosynthesis.
In the amazingly successful set of theories which are popularly called the Big Bang theory, the early universe was very dense, and very hot. As it expanded, it cooled, and the quark-gluon plasma ‘froze’ into neutrons and protons (and other hadrons, but their role in BBN was marginal), which interacted furiously … lots and lots of nuclear reactions. The universe continued to cool, and soon became too cold for any further nuclear reactions … the unstable isotopes left then decayed, as did the neutrons not already in some nucleus or other. Most matter was then hydrogen (actually just protons; the electrons were not captured to form atoms until much later), and helium-4 (alpha particles) … with a sprinkling of deuterium, a dash of helium-3, and a trace of lithium-7.
The atoms in your body – apart from the hydrogen – were all made in stars … by stellar nucleosynthesis.
Stars on the main sequence get the energy they shine by from nuclear reactions in their cores; off the main sequence, the energy comes from nuclear reactions in a shell (or more than one shell) around the core. There are several different nuclear reaction cycles, or processes (e.g. triple alpha, s process, proton-proton chain, CNO cycle), but the end result is the fusion of hydrogen (and helium) to produce carbon, nitrogen, oxygen, … and the iron group (iron, cobalt, nickel). In the red giant phase of a star’s life, much of this matter ends up in the interstellar medium … and one day in your body.
There are other ways new nuclei can be created, in the universe (other than BBN and stellar nucleosynthesis); for example, when a high energy particle (a cosmic ray) collides with a nucleus in the interstellar medium (or the Earth’s atmosphere), it breaks it into two or more pieces (this process is called cosmic ray spallation). This produces most of the lithium (apart from the BBN 7Li), beryllium, and boron.
And one more: in a supernova, especially a core collapse supernova, huge quantities of new nuclei are synthesized, very quickly, in the nuclear reactions triggered by the flood of neutrons. This ‘r process’, as it is called (actually there’s more than one) produces most of the elements heavier than the iron group (copper to uranium), directly or by radioactive decay of unstable isotopes produced directly.
Like to learn more? Here are a few links that might interest you: Nucleosynthesis (NASA’s Cosmicopia), Big Bang Nucleosynthesis (Martin White, University of California, Berkeley), and Stellar Nucleosynthesis (Ohio University).
Plenty of Universe Today stories on this topic too; for example Stars at Milky Way Core ‘Exhale’ Carbon, Oxygen, Astronomers Simulate the First Stars Formed After the Big Bang, and Neutron Stars Have Crusts of Super-Steel.
Check out this Astronomy Cast episode, tailor-made for this Guide to Space article: Nucleosynthesis: Elements from Stars.