Why do farts stink?
I am answering this unsavory question mostly because the student who asked it asked me to answer it, and he was a student who demonstrated an admirable spirit of inquiry throughout the year.
People have a symbiotic relationship with numerous bacteria that live in our intestines. In fact, there are more bacteria cells in our bodies than human cells. Many of these bacteria live in our intestines and help is to break down food. There are many gasses produced as a byproduct of these processes, and farting (flatulence) is our main way of expelling these gasses. It has long been debated which of these gasses were most responsible for the smell, but recent research has shown that it is caused by hydrogen sulfide and other volatile sulfur compounds. This is why eating high-sulfur foods such as cabbage or eggs can result in stinky flatulence.
There is also the question of why people find sulfur compounds so malodorous. Flatulence does not have much sulfur in it, but we are able to smell it quite easily. Most likely our sensitivity to volatile sulfur compounds is adaptive because it helps us to avoid eating rotten meat and eggs.
There are a couple of other interesting compounds that contributes a little to the smell of flatulence, but quite a bit to the smell of feces: skatole and indole, both of which are produced by the bacterial breakdown of tryptophan in the intestines. In small amounts these compounds have a flowery fragrance, and they are found in many flowers – most notably jasmine and orange blossoms. In larger amounts they smell like feces. They tend to be most prominent in the feces of carnivores, and that is one of the reasons carnivore feces generally smells worse than that of herbivores. (Another reason is that many carnivores have glands that add distinctive aromas to their feces to help them mark their territories.)
One of the most interesting characteristics of skatole and indole is that they make smells linger. This is why it is so hard to get the stink off of your shoes when you step on dog poop. It is also the reason that people who make perfume add these chemicals to their products. If you make your own fragrance from pure essential oils, it will be strong at first, then will quickly fade. Commercial perfumes can last all day, largely due to the addition of skatole and indole.
I once speculated that animals that harbor a large amount of skatole- and indole-producing bacteria do so because it is adaptive; it would make the territory-marking characteristic of their feces last longer. I cannot find any research to back up my hunch, and there seems to be some animals (Homo sapiens, for example) that produce large amounts of skatole but who are not known to mark their territories this way (although we may have in our past).