After the small-mass star evolves into a red giant, it will gradually diffuse the outer gas into the universe, exposing the core of the central high-temperature star, that is, the white dwarf. These drifting outer gases will form a cloud-like nebula material wrapped around the core of the central star in a certain period of time.
After the massive star evolves into a red giant, it will quickly throw away its outer gas in the form of a supernova explosion, and the central star core will further contract to form a neutron star or a black hole. The thrown material is scattered in space and can also form a cloud nebula.