A nest box is a 1x1 building that a tame, egg laying creature will claim and use to lay eggs in. Nest boxes are created using a single piece of wood or stone at a craftsdwarf's workshop, a single bag of sand (and optional crystal/pearlash) at a glass furnace, or a single bar of metal at a metalsmith's forge. Unplaced nest boxes are stored in the tool section of a finished goods stockpile.
The box will then be claimed by an egg-laying animal when it is ready to lay eggs. The animal that claims the nest box will periodically lay eggs into the nest. This process is very quick (< 1 day) and the eggs are ready to be collected immediately if they are to be cooked, but require time to hatch if you wish to start a breeding program.
If dwarves have access to the nest, a dwarf with the food hauling labor enabled will then remove the eggs and take them to a food stockpile and the animal will vacate the nest until it is ready to lay again. If a dwarf does not collect the eggs, the animal will remain on the nest box until the eggs hatch, after which it will also vacate the nest box until it is ready to lay again. In either situation, the nest box remains claimed by the animal. To free the nest for rapid turn around of eggs from a single box, deconstruct the nest after the eggs are collected or hatched and rebuild it - a different animal, ready to lay, will claim the nest box and immediately lay a clutch of eggs.
A nested female will lay eggs regardless of the presence of a male of the same species, however the eggs will not be fertilized unless a male is present. Eggs will hatch only if the dwarves can be prevented from collecting them out of the nest box and hauling them to be eaten. To achieve this, eggs can be forbidden, or access to the nest box can be blocked with locked doors, or eggs can be forbidden as a cooking ingredient on the Kitchen tab of Status screen and disabled in all food stockpiles.
There is no way of telling whether or not eggs have been fertilized, but if they sit in a nest box for more than two seasons, they are unlikely to ever hatch. Eggs do not appear to go rotten and can be collected and cooked after two or more seasons without generating miasma.