What happens when you add heat to matter? What about when you take it away?
Heat are energy possessed by atoms as they vibrate/move. This is indicated by temperature. For ideal gas, you can equate kinetic energy of molecule with energy associated with temperature (kT energy ) ...
From that, you can derive the expression for velocity of molecule in terms of temperature. (read this for more details:http://hyperphysics.phy-astr.gsu.edu/hbase/kinetic/kintem.html)
Energy from one molecule can be transferred to another molecules through collision. When you make two surface contact each other (like hot water and ice), the molecules inside hot water vibrate and collides with molecules inside ice. This effectively transfers the energy from hot water to ice.
Generally, the direction of energy transfer is from higher temperature surfaces to lower temperature surfaces.
When you are taking heat away from a body (like in refrigeration), you are manipulating temperature of two different material to force the direction of heat transfer in a particular direction. In the case of refrigeration, you expand the refrigerant (like ammonia) until the temperature drops. This drop in temperature forces the heat to travel from contents inside the fridge to the refrigerant. Hence, the contents inside fridge gets cooler and the temperature drops