To understand the function of the skin, one first has to know that the skin is made of layers. These layers create a protective sheath on the outside of the body. Because skin covers almost the entire body, notable exceptions being the eyes, it is the largest organ in the human body, a part of the integumentary system.
The epidermis is the outer layer of the skin, covered in dead epithelial cells (the stratus corneum) that take bacteria with them when they are shed. These cells absorb water for moisture, but the epithelium as a whole is a watertight barrier, protecting the tissues from damage, infection, and water loss. The epithelial cells rise to the outer layer as they die. The epidermis contains four to five layers through which the epithelial cells mature, die, and are shed leaving behind protein used in the skin's functions.
A basal epithelial cell layer (stratum basale) under the epidermis gives rise to the epithelial cells, creating the epidermis as described above. The skin cells and epithelium receive nutrients and oxygen from blood vessels and capillaries in the dermis. The dermis is the thicker inner layer of the skin. It is made mostly of connective tissue and contains many of the other components of the integumentary system as described below.
The skin contains receptors for the sense of touch, making it a sensory organ. This sense provides information about the body's external environment temperature, pain, pressure, and whether the body is in air or water, as well as which parts are affected. There are two types of nerve endings that act as receptors and are mostly present in the dermis of the skin, the thick inner layer that rests on the underlying fatty tissue (the subcutaneous fat layer): free nerve endings and encapsulated nerve endings. A highest receptor density is found in the hands and face, making them more sensitive.
The encapsulated nerve endings are free nerve endings encapsulated by connective tissue that sense touch and pressure. There are different types of encapsulated nerves. Merkel discs and Meissner corpuscles sense touch; Ruffini corpuscles and Pacinian corpuscles sense pressure and vibration. Free nerve endings sense pain, heat, cold, and intense stimuli depending on the layer of the skin where they occur. In the dermis, the nerves sense temperature. In the epidermis, the nerves sense pain. Wetness is a combined sense of temperature and pressure.
The receptors tend to sense changes in the environment, adapting to new conditions. This is why going out into the cold does not feel as cold after awhile, but entering a once comfortable room afterwards feels very warm. Pain and intense stimuli can also be adapted to, resulting in a numbing of the sense to that stimulus.
In the dermis are glands that produce sweat and oil onto the skin surface, keeping it moist and releasing excess minerals and toxins. Hair follicles are present in the dermis, extending hair through the epidermis. In some species, hair plays a role in temperature control, camouflage, and protection. The hair itself is made from keratinizing epithelial cells (skin cells) laying down protein. Nails (fingernails and toenails) are similar in composition; they protect the sensitive ends of the fingers and toes.
Also in the epidermis are melanocytes and immune cells. The melanocytes are responsible for skin pigmentation, producing the dark compound melanin. The concentration of melanin in the skin also affects the production of Vitamin D, a vitamin involved in calcium and phosphorous modulation in the body. The vitamin is produced as the result of a chemical reaction with cholesterol in response to sunlight (ultraviolet waves). The immune cells engulf invading pathogens and foreign particles before they reach the bloodstream or internal organs, preventing infection.