You sweat when it is hot or humid, and when you exercise vigorously. The reason is that your body works best when its temperature is about 98.6 F. when your body gets hotter than that, your brain wants your body to stay cool. So, the part of your brain that controls temperature, sends a message to your body, telling it to sweat.
Sweat is produced by glands in your skin called sweat glands. Sweats is made almost completely of water, with tiny amounts of other chemicals, salts, and sugar. It leaves your skin through tiny holes called pores. When sweat is exposed to air , it evaporates, and as it does, your skin cools down, to bring you relief from the heat.