Vitamin D is produced by the body when the skin is exposed to sunlight.
The process begins when ultraviolet B (UVB) radiation reaches the skin. It changes a cholesterol-related compound called 7-dehydrocholesterol into previtamin D3, which then becomes vitamin D3, or cholecalciferol. This synthesis occurs mainly in keratinocytes within the epidermis.
Vitamin D helps the intestines absorb calcium and phosphate, minerals essential for bones, teeth, muscles, and many cellular functions. The liver and kidneys further process vitamin D into forms the body can use. People can also obtain it from foods, fortified products, and supplements.
A common mix-up is assuming any sunlight exposure produces the same amount. UVB is the key wavelength, and glass blocks most UVB, so sunlight through a window is not an efficient source. Season, latitude, skin pigmentation, clothing, age, and sunscreen also affect production. Excessive sun exposure is not a safe way to pursue vitamin D because ultraviolet radiation increases skin-cancer risk.