Miasma is a cloud of purple stench that makes your dwarves unhappy. It is caused by rotting items, and only occurs in subterranean areas. It does not pass through closed doors. To avoid miasma, either keep anything rotten above ground or have a subterranean refuse pile in a room with several doors to stop miasma propagation.
A rotten item is a corpse, body part or an item of food that has spoiled, either from not being in a stockpile (for food) or just over time (for corpses and body parts). Body parts of living dwarves may also be marked as rotten if they are affected by a syndrome that causes necrosis. The afflicted body part produces miasma from time to time.
Prepared food, meat, cheese, eggs, and prepared fish will rot, while plants will wither instead of producing miasma. The only places where food will not rot are a stockpile, a trade depot, the embark wagon, and while being carried by a dwarf, caravan pack animal, or wagon. Additionally, eggs will not rot in a nest box.
Other food categories do not rot. However, raw fish will rot no matter where it is stored, which is why it's important to prepare fish as quickly as possible.