Energy is only created where the overlying matter provides enough pressure to heat the star to about 10 million degrees kelvin. At or above such temperatures, various nuclei can be forced close enough together to bond or fuse, releasing energy and forming heavier elements. For example, hydrogen fuses into helium, and helium fuses into carbon. The sun shines due to energy created by hydrogen fusion. Stars come in all masses, ranging from 0.08 solar mass to about 120 solar masses.
All stars begin their lives by fusing hydrogen into helium in their cores.
Stars with less than about 0.5 solar mass don't have enough matter to compress the helium further. Once such a star's hydrogen has been fused into helium, fusion stops and the helium star just cools off. More massive stars create enough internal pressure to compress their helium-rich cores until the temperature there is high enough to fuse helium into carbon. Like more powerful car engines, the fusion rate and the resulting energy output of more massive stars can run rings around the output of the sun. For example, while fusing hydrogen into helium in its core, a star with 10 times the sun's mass emits 10,000 times as much energy per second as the sun.