Nucleosynthesis is the process by which elements are formed through nuclear reactions in stars. This process occurs during various stages of a star's life cycle, including during its formation and explosive death. For instance, during the Big Bang, lighter elements like Hydrogen and Helium were created, while heavier elements are formed in the cores of stars through fusion reactions.
When massive stars exhaust their nuclear fuel, they can explode in a supernova, scattering newly formed elements into space. This enriches the interstellar medium, allowing for the formation of new stars and planets, and ultimately contributing to the chemical diversity of the universe.