A lot of people are answering chemically but I’ll try and answer physiologically.
The cooling and heating acts to “compress” and then “release” on the afflicted area. This wave of compression and release is like a massage that will get blood flowing through the area. The intention is to 1) use this blood flow to flush out localized lactic acid (Or lactose dehydrogenase) and 2) to encourage aerobic metabolism by bringing more fresh blood with oxygen to the site.
Latest Answers