Stars explode in a few different ways. It depends on the mass of the star. For instance, when a medium star like our Sun runs out of hydrogen fuel in the core to fuse in to helium (this is how stars are powered), it will collapse into a dense ball and then bounce back out again. Most of the gas will puff outward and surround the dense core of the Sun, which will become a white dwarf. The surrounding gas hovering about will form something called a “planetary nebulae”- nothing to do with planets. Ask later. This isn’t so much an explosion as the sun burping its outer gas shell in every direction at once.
However much larger (giants and super giants) do explode in the form of “supernovae” (this is how heavy elements like uranium are formed!). When they collapse (after they run out of fuel) the gravitational energy is converted to heat and kinetic energy EXTREMELY rapidly, and the star’s gas is flung far and wide. Instead of a white dwarf left over at the core of the explosion, a neutron star is formed (imagine the mass of the Sun compacted to the size of Dublin, and you have a neutron star). But, for the most massive stars, their supernovae form “black holes”, which are so dense that at their centers, we can not describe how strong gravity is… (mathematically is is infinite!) And their “surfaces” are described by the place where if a light beam comes too close, it will be essentially sucked into the black hole. Light travels ~300000000 meters per second, so for something going that fast to be trapped by gravity, is pretty amazing.