How is geothermal energy formed?

hot magma heating up the earth and rocks which is transferred into water and stuff!