Energy in stars are formed by the fusion reactions in the core of the stars which produce enormous energy and glows stars hot and bright. Hydrogen is the main fuel of stars.
Nuclear fusion is the reactions of nuclei combining together to form heavier nuclei. During the fuse, lots of energy is given out as heat and light. Combining nuclei will form a new element. Deep in its core, the heat output and huge gravitational pull keep the hydrogen hot enough and compressed enough to maintain fusion. In sun, nuclear fusion occurs only at 15 million degrees
Nuclear reactions depends on the size of stars.
Small stars: The smallest stars only convert hydrogen into helium.
Medium-sized stars (like our Sun): Late in their lives, when the hydrogen becomes depleted, stars like our Sun can convert helium into oxygen and carbon.
Massive stars (greater than five times the mass of the Sun): When their hydrogen becomes depleted, high mass stars convert helium atoms into carbon and oxygen, followed by the fusion of carbon and oxygen into neon, sodium, magnesium, sulfur and silicon. Later reactions transform these elements into calcium, iron, nickel, chromium, copper and others. When these old, large stars with depleted cores supernova, they create heavy elements (all the natural elements heavier than iron) and spew them into space, forming the basis for life