Types of vitamin D
Vitamin D can be said to be of 5 types, but if the type is not specified, it usually means Vitamin D3, which is synthesized by us humans, or Vitamin D2, produced by plants, or a mixture of both.
Vitamin D, the sunshine vitamin, is essential for bone development and maintaining their strength. It can also be synthesized in our bodies - another reason the scientist community is divided over its classification, and whether to call it 'essential' or not.

Its history is similarly marred with controversy and confusion. An experiment performed on dogs by Sir Edward Mellanby, proved that bone diseases such as rickets, can be cured by feeding them cod liver oil. But the credit for curing the disease went to vitamin A. In 1922, Elmer McCollum repeated the experiment with cod liver oil, in which Vitamin A was destroyed. The positive results repeated themselves, and thus, it was discovered that another compound was responsible for strengthening the bones. Elmer named this compound vitamin D .

As mentioned earlier, vitamin D is also called calciferol, and usually means Vitamins D2 or D3, or a mixture of the two, but can be classified into 5 types based on its composition. Here is a brief overview of the different types of Vitamin D.
Vitamin D1
Molecular structure of D1(lumisterol and ergocalciferol)
When Nobel laureate Adolf Windaus first discovered the different forms of Vitamin D, he named them Vitamin D1, D2, and D3. Vitamin D1 is actually a mixture of equal parts of ergocalciferol (vitamin D2) and lumisterol - a steroid compound produced by exposure of ergosterol to ultraviolet radiation. Not being a pure substance, it is not considered a 'type' of vitamin D anymore.
Vitamin D2 (Ergocalciferol)
Molecular structure of D2(ergocalciferol)
Vitamin D2 is synthesized by plants, fungus, and small invertebrates, on exposure to UV radiation, but is not generally found in vertebrates. It differs from cholecalciferol on account of a side chain - vitamin D2 has a double bond and a methyl group on its side chain, whereas, both are absent in D3.
As it is obtained by irradiation of yeast, lichen, or certain fungi such as mushrooms, it is considered to be a 'vegan' vitamin D. It is often added to bread, milk, and other food products, to fortify them. Some experts though, doubt its bio-availability and potency, as it is not the form synthesized by the human body. It behaves differently than vitamin D3, and has different by-products. But studies done on the comparison of the two forms and their effects on the body, are till date, inconclusive.
Vitamin D3 (Cholecalciferol)
Molecular structure of D3(Cholecalciferol)
Cholecalciferol is the vitamin synthesized in our skin on exposure to UV radiation. Once synthesized, it is converted into calcifediol, a prehormone, by the liver. It is then converted into calcitriol, the active form of Vitamin D, by the kidneys. Calcitriol is a steroid hormone which increases the absorption of calcium from the gastrointestinal tract.
Vitamin D3 is made/obtained synthetically for fortifying food or to make vitamin supplements. For this purpose, it is often derived from lanolin (a fatty substance that coats a sheep's wool) by irradiating it with ultraviolet light.
Vitamin D4 (22-dihydroergocalciferol)
Molecular structure of D4(22-dihydroergocalciferol)
This recently-discovered vitamin is observed in certain types of mushrooms, such as portabella, oyster, and maitake mushrooms, on exposure to UV light. Not much is known about its functions or effects, as it is not found in humans. Some speculate that it might be a vitamer - a compound closely resembling a vitamin with similar functions and mode of action.
Vitamin D5 (Sitocalciferol)
Molecular structure of D5(Sitocalciferol)
Sitocalciferol is a prehormone, and is related closely to Vitamin D3. It is being researched for its efficacy in preventing cancerous growth of cells. Vitamin D is thought to inhibit the growth of tumor and consequently prevent cancer. But the concentration of the vitamin required also puts the patient at risk of hypercalcemia. Vitamin D5 has a very low calcemic activity, and thereby, could be used for preventing cancer.
Vitamin D can be obtained by increased exposure to sunlight, and including foods like fish, cod liver oil, milk, eggs, fruits, and vegetables in the diet.
Some of its benefits are: aids in absorbing nutrients, balances calcium levels, keeps blood pressure in check, prevents muscle spasms, helps prevent respiratory infections, reduces stress and tension, helps insulin secretion, helps combat depression, prevents osteomalacia and rickets, good for skin health, improves kidney functioning, prevents cancer by controlling the abnormal multiplication of cancer cells, and improves bone and muscle strength, besides other things.
Vitamin D is the only vitamin synthesized in the body, but functions more like a hormone by regulating the levels of calcium and phosphorous. It closely resembles steroids like cholesterol, progesterone, and cortisone, in its chemical structure. It also has many forms, vitamers and analogs, making its classification difficult and confounding.