Gravity pulls more strongly on denser materials so denser materials are at the center of things. Earth's core, at its center, is denser than its crust. The lowest layer of the atmosphere is denser than the upper layer. Earth's liquid metal outer core has convection, which generates the magnetic field.