How do black holes form in space?
Black holes form through several mechanisms. The most common way is when a massive star, typically more than 20 times the mass of our Sun, exhausts its nuclear fuel and can no longer support itself against gravity. The core collapses catastrophically in a supernova explosion, and if the remaining core mass is sufficient, gravity overwhelms all other forces and compresses the matter into a singularity, forming a stellar black hole.
Supermassive black holes, found at the centers of galaxies, likely formed from the mergers of smaller black holes and the direct collapse of enormous gas clouds in the early universe. Primordial black holes may have also formed from density fluctuations shortly after the Big Bang, though these remain theoretical.