|This article is about the current version of DF.|
Miasma is a cloud of purple stench that makes your dwarves unhappy. It only occurs in subterranean areas (specifically, "Dark Subterranean" tiles; whether a tile is "Inside" or "Outside" makes no difference), and is caused by rotting items. It does not pass through closed doors.
 Rotten items
A rotten item is a corpse, body part or an item of food that has spoiled, either from not being in a stockpile (if food) or just over time (if a corpse or body part).
Often a job in a kitchen, still or farmer's workshop will be canceled with the announcement "...needs unrotten (item)". That doesn't mean you only have rotten ones, it means there is not an appropriate item that is available. Items that are forbidden, marked for dumping, or that have no path will be disregarded for workshop tasks.
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.
 Food rot
Prepared food will rot the same as meat, cheese, eggs, and prepared fish, but plants will wither instead of producing miasma. The only place where food will not rot is in a stockpile, in a trade depot, in the embark wagon, when used as a reaction component, or while being carried by a dwarf, caravan pack animal, or wagon. Additionally, eggs will not rot in a nest box. It does not matter if the food is in a container; a barrel or pot full of meat left in a corridor will rot.
While you'd expect milk, fat, and tallow to rot, it seems that they do not. Nor do any of the other categories of food, including flours, drinks, seeds, and rock nut paste. A raw fish will rot no matter where it is stored, which is why it's important to prepare fish as quickly as possible.
 Miasma propagation
Once miasma has been generated (there is a purple square), it will spread for a while, eventually disappearing. This is true even if the original source has been removed: you can still have a spreading cloud of miasma even after you've cleaned up the dead goblin or whatever. The spread of miasma is only north, south, east, west, up, or down. It will not pass through diagonal openings. It will pass through open doors and floor hatches, and it will pass through grates.
 Avoiding miasma
To avoid miasma, either keep anything rotten above ground or alternatively have a subterranean refuse pile on its own in a room with several doors; this should halt the miasma's advance (although the room itself will still stink up). It will also not spread diagonally, so one possible solution is to have the only entrance be diagonal.
Alternately, excavate the roof of your refuse pile/butcher's shop/fishery so that it is open to the surface, then build a floor over it. The tiles underneath will forever count as "Light Above Ground" and therefore will not generate miasma. (For style points use a transparent roof.) See tile attributes for more information.
Another option is to have a long garbage chute where refuse is dumped down. If it is long enough the miasma will not be able to reach all the way to the top, preventing your dwarves from getting unhappy thoughts.
A creative way of constructing garbage chutes is to separate the garbage area and dumping area (where dwarves are) with hatches linked to a pressure plate. That way garbage will land on the hatch, which will open (triggered by dwarf returning to his duties stepping on a plate), letting it fall down and then close, keeping all the miasma inside. This allows one to construct a short, yet non-smelly chute.
Another option for a short non-smelly chute is to let the chute be separated diagonally from the dumping square(s). Since miasma does not travel across corners, this allows a chute stretching across 2 z-levels to be completely miasma free, without needing additional mechanisms.
Example #1 WWWWWWW W=Wall WWWWWOW .=Floor ....-WW O=Channel WWWWWWW -=Floor with dumping zone
Example #2 WWWWWWW W=Regular Wall .=Regular floor WWWWMQW M=Wall with dumping zone ....--W Q=Channel with dumping zone WWWWWWW -=Floor with dumping zone
If you do encounter miasma coming from a kitchen you can stop more by deconstructing the kitchen and making the area the kitchen was in a food stockpile. Miasma from a kitchen is (likely) caused by cooked food being left inside the kitchen because of not having food containers to put it in. Butcher shops suffer from the same problem.
 Related bugs
Note that dwarves interrupted in the middle of a meal will abandon their food. Food abandoned in this manner can never be interacted with (picked up, stored, or dumped) by any dwarf ever again, including the dwarf who abandoned it. Bug:1299 If the food is abandoned underground, it will eventually rot and generate miasma. This is an especially frequent occurrence with soldiers, who will often be interrupted while consuming their rations when a training class begins. One workaround for soldiers is to use the military supplies tab to prevent them from carrying food.
The utility DFHack includes a command "cleanowned" to clear ownership and dump all owned items that are on the floor or rotting. This can help if you're dealing with miasma from this bug.