Sweating is basically a more efficient cooling mechanism for your body. You produce heat all the time (especially when you’re moving –> sports), however you must not overheat. If outside temperature gets closer to the body temperature, surrounding air cannot take up enough of your produced heat to maintain your body-temperature. So you start to sweat, as the fluid takes a lot of heat from your skin when evaporating (the exact amount is called “heat of evaporation” or “enthalpy of vaporization”)
Latest Answers