Rocks are divided into three main types based on their origin: igneous, sedimentary, and metamorphic. Igneous rocks form from the cooling and solidification of magma either underground (intrusive/plutonic rocks like granite) or on the surface (extrusive/volcanic rocks like rhyolite and basalt). Sedimentary rocks form from the compaction and cementation of sediments. Metamorphic rocks form from the alteration of existing rocks via heat, pressure, and chemical reactions. Rocks continuously cycle between these three types through geological processes like erosion, deposition, and tectonic activity.