How does earth's core work?
The heat comes from the formation of the Earth, radioactivity and friction as it drags dense materials down with gravity. The iron-nickel alloys in the core also produce the Earth's magnetic field.
The Earth was probably formed by core accretion. Early in the solar system's history, small particles floating in space began to attract each other and clump together, gaining more mass so more gravity so more attraction. The ball of stuff would grow. Dense materials with a greater gravitational attraction would be forced into the center or core, and lighter elements would remain around the outside as the crust. This is why the core now is a huge lump of iron, while the crust is mostly silicon, oxygen and carbon.
Since the rest of the Earth is so heavy, the pressure bearing down on the inner core is immense, which is why it is pressed into a solid, even though it is way past the melting point of ordinary iron - the core is 5700K.
Heat from the core is partly due to energy which has not yet been lost, leftovers from when the planet was accreted. This energy is slowly emitted, and heats the Earth from the very inside.
There is also energy from friction, as dense materials are still being pulled by gravity down to the core, though at a slower rate than before because there is now so much stuff in the way. This means there is a great gravitational energy, which can be translated into kinetic, frictional and, most importantly, heat.
Finally, the core and mantle both have some radioactive materials, like uranium and thorium, which decay and release large amounts of energy. This is actually where most of the heat from inside the Earth originates.
Earth's magnetic field is also thought to come from the core. Around the outside it is still fluid - this is the outer core - and it's made of iron and nickel, both of which are magnetic metals. The iron-nickel alloys flow, and move the Earth's magnetic field. This is why geophysicists predict the Earth's magnetic fields will flip at some point.