The Sun will not exactly "explode" when it reaches around 5 billion years of age, but it will undergo a significant transformation known as a supernova. It's important to note that this is not applicable to the Sun specifically, but rather to much more massive stars.
The Sun is classified as a main-sequence star, and it belongs to a category of stars called low-mass stars. These stars have relatively small masses compared to more massive stars. When low-mass stars like the Sun exhaust their nuclear fuel (primarily hydrogen), they do not explode as supernovae.
Instead, what happens to low-mass stars like the Sun is a gradual evolution into a different phase known as a red giant. As the Sun exhausts its hydrogen fuel in its core, it will start to fuse helium into heavier elements in a shell surrounding the core. This fusion process causes the outer layers of the Sun to expand, turning it into a bloated red giant. During this phase, the Sun will engulf the inner planets, including Earth.
Eventually, the Sun will shed its outer layers, forming a cloud of gas and dust called a planetary nebula. The remaining core, known as a white dwarf, will be extremely dense and hot but will no longer undergo nuclear fusion. It will gradually cool down over billions of years, eventually becoming a cold, dark remnant known as a black dwarf.
It is worth noting that more massive stars, significantly larger than the Sun, do experience a supernova explosion at the end of their lives. This explosive event occurs when these massive stars run out of nuclear fuel and the core collapses under its own gravity, leading to a powerful explosion that releases an enormous amount of energy.
In summary, while the Sun will undergo significant changes as it ages, it will not "explode" like a supernova. Instead, it will evolve into a red giant, shed its outer layers, and leave behind a white dwarf as its final stage of stellar evolution.