Caves are most commonly formed by the process of erosion. Caves may also be formed by the waves, lava flows or by bacteria that produce acid.
The majority of caves are formed in what is called karst, which is an area made of dolomite or limestone that has underground streams and sinkholes. Rainwater that has combined with carbon dioxide while still in the atmosphere falls and seeps through cracks. With the help of more carbon dioxide, it creates an acid that is weak but capable of eating away at the rocks over time. After millions of years, this acid hollows out areas that eventually join to form a cave.
Caves that form along the ocean shore are called sea caves. These caves are formed by the waves hitting the cliffs and eroding the soft rock over time.
Lava tubes are caves that are formed when a lava flow cools along the outer edges faster than in the middle. This forms a crust around the flow of lava, which hardens and creates a cave.
Certain bacteria feed off of oil deposits and produce a gas which forms a strong acid when it mixes with oxygen. This acid erodes rocks and creates caves that require special equipment including a supply of oxygen to visit.