The definition of temperature and how heat is related is the subject of the zeroth law. This law postulates that there is a state function, called temperature, T, for which the following schematic represents its properties.
Below you will see two diagrams a set of systems. What is constructed is an isolated system with two closed systems inside. Initially the two systems are isolated from each other and are at different temperature. For illustration, in diagram 1 the temperature of system number 1 is higher than in system 2, i.e.
initially: T1 > T2.
Now we will let the two closed systems come in contact with each other and allow heat to "flow" from system 1 to system 2. In other words, the walls between the two systems are not insulating. The zeroth law says then that the flow of the heats will be from system 1 to system 2. The temperature of system 1 will decrease and the temperature of system 2 will increase until:
finally: T1 = T2
The zeroth law was not stated initially because this is such a obvious concequence of the property of temperature and was assumed.