During the formation of the moon, due to the giant impact, the earth was further heated up. It is through the process of differentiation that the earth forming material got separated into different layers. Starting from the surface to the central parts, we have layers like the crust, mantle, outer core and inner core. From the crust to the core, the density of the material increases.