Well water comes from deep underground. The water table may sit on a sulfur deposit. Sulfur dissolves in water, forming hydrogen sulfide gas. Adel L. Pfeil of Purdue University's Cooperative Extension Service notes that this occurs more frequently around oil or coal deposits. The deeper the well, the more the possibility of sulfur.
Hydrogen sulfide does not become trapped in water, but rather is released quickly. This is very much akin to opening a soda bottle that has been shaken up. When you smell the rotten-egg odor, its the hydrogen sulfide gas releasing from the water, since this gas has a distinctive smell.
Because hydrogen sulfide quickly releases from water, placing an aerator just after the well alleviates some of the problem. An aerator shoots a water spray into the air, releasing the gas. The water drops back down into a tank and is pumped to the house. Pfeil cautions, however, that this process removes most, but not necessarily all, of the hydrogen sulfide. Furthermore, the rotten egg smell is evident around the aerator.
Various water softeners also remove hydrogen sulfide. These systems use various chemicals, such as potassium permanganate, or carbon filters to remove the hydrogen sulfide from the water.
A combination method uses both an aerator and a water softener/filter to remove hydrogen sulfide. First, the well water is pumped through an aerator. After aeration, the water enters the treatment softener/filter, which removes any residual gas. Finally, the water enters the house.