How are stars (like the sun) formed?
A star is considered a sun if it’s in the center of a system with planets orbiting around it. Stars are formed in very large dark clouds. These dark clouds are molecular clouds made primarily of hydrogen and carbon monoxide.
The clouds of gas – cold, dense gas – can be hundreds of light years across. Some piece of that cloud will start to become cool enough that it can’t support itself against its own gravity. It becomes gravitationally unstable, meaning it starts to collapse under its own gravity.
To form a star, it has to collapse by at least a factor of several million. As this little clump of gas starts to collapse to make a star, it sometimes gets a bit of angular motion and spins, with the spinning getting faster and faster as the collapse continues.
A protostar is a star in the process of formation. It has an equatorial disk, a band of materials around the central star body, spinning very fast. This draws materials and matter inward toward the central star.
Somehow the star has figured out how to divert a lot of this matter into what we call a bipolar jet. The jet carries away the angular momentum and allows matter to ultimately fall onto this central star. This whole process of how this matter is diverted into the bipolar outflow is still not fully understood.
So planets and stars are formed together simultaneously. Every star will have a system of planets, because the equatorial disk, or accretion disk, is what allows planets to condense out of and find their orbit around the central star. It’s also why the planets are mostly in a plane, called the equatorial plane, because they’re condensed out of the equatorial accretion disk.