Vitamin D is used as a general term for vitamins D2 and D3. Vitamin D is typically acquired from the sun, fortified foods like milk, breakfast cereals and orange juice, or foods like herring, sardines, wild-caught salmon, and fish liver oils. Most Americans do not meet daily recommended intake levels for vitamin D through their diet. It also may be difficult for people with certain skin tones or lifestyles to get the recommended amount of vitamin D because of sun exposure; the darker your skin tone, the less you can absorb from the sun. Or, if you're like most people, you likely work indoors and have made it a habit to reduce your exposure to the sun with SPF and hats. That's where supplements come in.
Here are the differences: Vitamin D2 (ergocalciferol) is synthesized from yeast and mushrooms and is less bioavailable throughout the body. Vitamin D3 (cholecalciferol) is the active and preferred form of vitamin D. Vitamin D3 is derived from the lanolin in sheep's wool and can be found in fatty animal-sourced foods such as fish or egg yolks.
That said, if you're vegan, you may want to take a supplement with vitamin D2 versus vitamin D3, as D3 is derived from animal sources.
Just know that getting even 10 minutes of sun exposure a day is good for your vitamin D production.