There are two types of sulfites (aka sulfur dioxide): natural and added.
Natural sulfites are produced during fermentation as a natural byproduct.
Added sulfites preserve freshness and protect wine from oxidation, and unwanted bacteria and yeasts.
Before you start blaming sulfites for your headaches... No, you are (probably) not allergic to sulfites. The FDA estimates that less than 1% of the US populate has a sulfite allergy, and those who do are most likely asthmatic. Meaning, your headache is probably because you drank too much and are dehydrated - time to chug some water!