When two bodies at different temperature are mixed, the hotter body loses while the colder one gains heat energy. It follows that, from the principle of conservation of energy, provided that no heat is lost to the surrounding, the amount of heat lost by the hotter body is equal to the amount of heat gained by the colder body. Heat lost by hot body (bodies) = Heat gained by cod body (bodies)
This statement is known as the law of heat exchange.