There are a couple of answers to the question, "How do black holes form?" Different types of black holes form through different processes. Stellar-mass black holes are born when very massive stars (typically tens of solar masses) explode in supernovae. These explosions are some of the most energetic phenomena in the universe. In a supernova, the outer layers of a dying star are violently ejected into space, while the remaining core collapses under its own weight to form a black hole.
The formation mechanism of supermassive black holes is still a topic of debate. While it is generally agreed that a black hole in the center of a galaxy could become supermassive by accreting matter and merging with other black holes, the origin of the progenitor black hole remains unclear. Perhaps supermassive progenitors were all originally stellar-mass black holes formed by the explosions of the first generation of extremely massive stars. Another model states that before star formation even ignited young galaxies, large gas clouds collapsed to form the first black holes. Yet another model suggests that primordial black holes, hypothetically formed by density fluctuations in the first moments following the Big Bang, are the seeds of supermassive black holes.