The odor of your stool is highly dependent on a number of factors, including how long it's been sitting in your colon, your diet, medications you may be taking and, in some cases, the presence of infection. Bacterial imbalance (dysbiosis) in the GI tract and undigested fat can also lead to a change in odor.
The most common cause of smelly stool is bacterial fermentation of the food in your intestines that produces foul-smelling sulfide compounds. Antibiotics can also change the smell of stool and give it a medicinal odor. More lethal causes of malodorous stool, and fortunately much less common, include inflammation of the pancreas (pancreatitis) and pancreatic cancer. Both these conditions can result in floating, foul-smelling stool with an oily sheen.
Diseases that cause malabsorption of nutrients like Crohn's, celiac disease and cystic fibrosis can also lead to foul-smelling stool. Infection with parasites such as giardia lamblia can cause stool to have a very unpleasant odor.
New onset of diarrhea associated with a foul odor should prompt an evaluation for infection, whereas fat in the stool associated with a foul odor should raise concerns about malabsorption or pancreatic disorders. For most people, smelly stool is simply a byproduct of the beans they had for dinner the night before.