Virtually all life on Earth is sustained by energy from sunlight. This energy is transmitted from sun to Earth in the form of electromagnetic radiation emitted by hot gas at the sun's surface. The sun is heated by nuclear fusion taking place within its core.
Like other stars, the sun is believed to have formed from a large cloud of gas that slowly contracted under the influence of gravity. Continuing contraction and compression superheated the gas to the point where temperatures were high enough to sustain nuclear fusion. From this point forward, the heat released by nuclear fusion counterbalances the influence of gravity so the size of the sun remains relatively stable.
The sun's core consists of plasma, gas so hot it has become completely ionized (i.e. the atoms have been stripped of their electrons). The protons (hydrogen nuclei) at these temperatures are moving so rapidly they can overcome their mutual repulsion and collide to form helium nuclei. This type of reaction is called nuclear fusion.
Nuclear fusion reactions convert mass into energy in a ratio determined by the famous formula, E=mc². Since c is the speed of light and c squared is a huge number, a very small amount of mass, when converted, becomes a large amount of energy. By heating the sun, nuclear fusion generates the energy radiated from the surface as electromagnetic radiation.