Dungeons generate naturally in the Overworld, at any level. For each chunk, 8 attempts are made to spawn a dungeon; it's possible but unlikely for multiple attempts to succeed.
For each attempt, a location and size (an open area of 5×5×3, 5×7×3, or 7×7×5) are chosen. The attempt succeeds if the following conditions are met:
The floor area (including under the walls) of the potential dungeon must be entirely solid.
The ceiling area (including over the walls) of the potential dungeon must be entirely solid.
The walls of the potential dungeon must have 2–5 openings (2-high air blocks) at floor level.
If the location passes, air and cobblestone are placed, then 3 attempts are made to spawn each of 2 chests. To spawn a chest, the chosen block must be empty and must have a solid block on exactly one of its four sides. The spawner is placed at the center of the dungeon.