Sweat, or perspiration, is a liquid made by the skin when the body is hot. Sweat is made in sweat glands under the surface of the skin. It comes out of tiny holes in the skin called pores. Sweat is mostly water, but it also contains some salts. 

The body makes sweat to cool itself down. It is part of the body's thermoregulation. The sweat takes the heat from the body when it evaporates (turns to gas).

Some people think sweat makes a person smell bad. Many people use special sprays to stop this from happening. Deodorants hide the odor of sweat. Anti-perspirants stop the body from sweating.

The sweat glands in our skin contains two different groups of sweat glands: apocrine sweat glands and merocrine sweat glands.

Perspiration, or sweat, is your body's way of cooling itself, whether that extra heat comes from hardworking muscles or from overstimulated nerves. The average person has over 4 million sweat glands in their skin. Sweat glands are distributed over the entire body, except for the lips, nipples and external genital organs. The sweat gland is in the layer of skin called the dermis along with other "equipment," such as nerve endings, hair follicles and so on.

Sweat glands
The sweat gland is a long, coiled, hollow tube of cells. The coiled part in the dermis is where sweat is made, and the long part is a duct that connects the gland to the opening or pore on the skins's outer surface. Nerve cells from the sympathetic nervous system are connected to the sweat glands. There are two types of sweat glands:

Eccrine - the most numerous type that are found all over the body, particularly on the palms of the hands, soles of the feet and forehead. They are smaller, are active from birth, and they produce a sweat with no proteins.
Apocrine - the ones in the armpits (axilla) and the anal-genital area. They are larger than eccrine glands and they normally end in hairs rather than pores. Also, they do not do anything until puberty.

How sweat is made
We are constantly sweating, even though we may not notice it. Sweating is your body's major way of getting rid of excess body heat, which is produced by metabolism or working muscles. The amount of sweat produced depends upon our states of emotion and physical activity. Sweat can be made in response to nerve stimulation, hot air temperature, and/or exercise. First, let's concentrate on how sweat is made in an eccrine sweat gland. 

When the sweat gland is stimulated, the cells secrete a fluid (primary secretion) that is similar to plasma -- that is, it is mostly water and it has high concentrations of sodium and chloride and a low concentration of potassium -- but without the proteins and fatty acids that are normally found in plasma. The source of this fluid is the spaces between the cells (interstitial spaces), which get the fluid from the blood vessels (capillaries) in the dermis. This fluid travels from the coiled portion up through the straight duct. What happens in the straight duct depends upon the rate of sweat production or flow: 

Low sweat production (rest, cool temperature) - Cells in the straight duct reabsorb most of the sodium and chlorine from the fluid. This happens because there is enough time for reabsorption. In addition, water is reabsorbed osmotically. So not much sweat reaches the outside. Also, the composition of this sweat is significantly different from the primary secretion. There is not as much sodium and chloride, and there is more potassium. 
High sweat production (exercise, hot temperature) - Cells in the straight portion do not have enough time to reabsorb all of sodium and chloride from the primary secretion. So, a lot of sweat makes it to the surface of the skin and the composition is close to, but not exactly like the primary secretion. The sodium and chloride concentrations are about half as much, and potassium is about 20 percent higher. 

Sweat is produced in apocrine sweat glands in the same way. However, the sweat from apocrine glands also contains proteins and fatty acids, which make it thicker and give it a milkier or yellowish color. This is why underarm stains in clothing appear yellowish. Sweat itself has no odor, but when bacteria on the skin and hair metabolize the proteins and fatty acids, they produce an unpleasant odor. This is why deodorants and anti-perspirants are applied to the underarms instead of the whole body. 

The maximum volume of sweat that a person who is not adapted to a hot climate can produce is about one liter per hour. Amazingly, if you move to a hot climate such as the American desert southwest or the tropics, your ability to produce sweat will increase to about two to three liters per hour within about six weeks! This appears to be the maximum amount that you can produce.

Function of sweat 
When sweat evaporates from the surface of your skin, it removes excess heat and cools you. This is actually due to a neat principle in physics, which goes like this. To convert water from a liquid to a vapor, it takes a certain amount of heat called the heat of vaporization. This heat energy increases the speed of the water molecules so that they can escape into the air. For water, this value is 540 calories/gram or 2.26 x 106 joules/kilogram. So, if you can produce one liter of sweat, which is equal to 1000 g or 1 kg (density of water is 1 g/ml or 1 kg/l) in one hour, then 540,000 calories of heat can be removed from your body. This is an extreme example using the maximum amount of sweat that a person can make. Typically, all of the sweat does not evaporate, but rather runs off your skin. In addition, not all heat energy produced by the body is lost through sweat. Some is directly radiated from the skin to the air and some is lost through respiratory surfaces of the lungs. 

A major factor that influences the rate of evaporation is the relative humidity of the air around you. If the air is humid, then it already has water vapor in it, probably near saturation, and cannot take any more. Therefore, sweat does not evaporate and cool your body as efficiently as when the air is dry. 

Finally, when the water in the sweat evaporates, it leaves the salts (sodium, chloride and potassium) behind on your skin, which is why your skin tastes salty. The loss of excessive amounts of salt and water from your body can quickly dehydrate you, which can lead to circulatory problems, kidney failure and heat stroke. So, it is important to drink plenty of fluids when you exercise or are outside in high temperatures. Sports drinks contain some salts to replace those lost in the sweat.

Effect of emotion 
Sweating responds to emotional state. So when you are nervous, anxious or afraid, there is an increase in sympathetic nerve activity in your body as well as an increase in epinephrine secretion from your adrenal gland. These substances act on your sweat glands, particularly those on the palms of your hand and your armpits, to make sweat. Thus, you feel a "cold" sweat. Also, the increased sympathetic nerve activity in the skin changes its electrical resistance, which is the basis of the galvanic skin response used in lie detector tests.

Excessive sweating
Excessive sweating usually occurs on the palms of the hand or the armpits. If it is not caused by emotional or physical activity it is called diaphoresis or hyperhidrosis. It is often an embarrassing condition. The cause or causes are unknown. The condition may be due to the following:  

hormonal imbalances (e.g., menopause in women) 
overactive thyroid gland (The thyroid hormone increases body metabolism and heat production) 
certain foods and medications (e.g., coffee with its high amounts of caffeine) 
overactivity of the sympathetic nervous system 
The condition can be treated.

Other websites
 

Integumentary system