It comes from within the sun itself. Like other stars, the sun is a big gas ball made up mostly of hydrogen and helium. The sun generates energy in its core in a process called nuclear fusion. Four hydrogen nuclei fuse to become one helium atom. But the helium atom weighs less than the four nuclei that combined to form it.
Some matter is lost during nuclear fusion.
The lost matter is emitted into space as radiant energy. It takes millions of years for the energy in the sun's core to make its way to the solar surface, and then just a little over eight minutes to travel the 93 million miles to earth. The solar energy travels to the earth at a speed of 186,000 miles per second, the speed of light. Only a small portion of the energy radiated by the sun into space strikes the earth, one part in two billion. Yet this amount of energy is enormous.