Craters can be formed in many various ways.
Craters are caused by impact of asteroids, that indents the surface.
When a Asteroid hit's a rocky planet: Such as the moon. It makes an indetion to the surface of that planet.
Asteroids aren't the only thing that causes craters.
Craters can also be formed by volcanic explosions. Depending on how damaging the volcanic explosion is, the volcano will collapse due to structure damage from the explosion. Which this is called a volcanic crater.
I hope this helps!
-LizzyIsTheQueen