Dwarves that have been awake for a long time will eventually become tired and desire sleep. Along with eating and drinking, sleep is a necessary maintenance activity that your dwarves will need to perform at intervals, a few times every season. Drowsy dwarves are indicated by a blinking gray arrow. Dwarves who are unable to sleep for 6 months may go insane.
Dwarves that are tired will work more slowly, and produce poorer-quality results. However, dwarves generally will not remain drowsy for long; upon getting sleepy they usually finish their current task, find a bed, and fall asleep. If no bed is available, they will fall to the floor immediately after completing their last task (drunken dwarves sleeping on barrels of hard liquor are quite common). If there is an unassigned bed located closer to them then their assigned room, they will sometimes choose to sleep there instead; thus, hospitals often find themselves "treating" exhausted dwarves, necessitating extra beds to accommodate truly wounded dwarves.
As one might imagine, having to sleep in the dirt is not a happy occurrence, and will give your dwarves unhappy thoughts. On the other hand, sleeping on a nice bed, in a nice room will give them a happy disposition upon waking. The exact arrangement of living conditions (bedroom design) is a big part of fortress design; some players lavish their dwarves' rooms and see it as an easy way to increase their happiness, some see bedrooms only as necessary provisions, and some do away with them entirely, preferring easier-to-create, easier-to-maintain public dormitories instead (these do have the advantage of making vampire spotting a piece of cake). Nonetheless, the need to prevent your dwarves from sleeping under the stars more than a few times at the very beginning is a universally agreed-upon point of importance.
Dwarves do not follow natural sleeping cycles. There is no "night" in fortress mode, beyond references in the form of night creatures (in adventurer mode, however, this is a different story entirely). Instead, they will sleep according to their own internal clock. At the very beginning, dwarves that arrive at the same time will tend to nod off at the same time, but as time progresses, they will diverge into their own cycles. After some time, at most a quarter of the fortress may be asleep at a time.
Other unhappy thoughts associated with sleep are caused by being tired, collapsing from exhaustion, and being disturbed by nearby noise. Noise can cause uncomfortable or troubled sleep, or wake the dwarf entirely, with increasingly negative thoughts.
Collapsing from exhaustion only really happens in the military. Dwarves on active military service (stationed or attacking) will forgo sleep for duty, but will be unhappy when they finally do get to sleep. Military dwarves can nonetheless spontaneously fall to the ground unconscious if they are exhausted. Since dwarves do not come with portable pillows, cannot munch on rations or take swigs from flasks as they can to relieve hunger and thirst, the need to sleep is the primary limiting factor on how long you can keep your military dwarves on high alert before they fall dangerously unconscious.
Sleeping is not the same thing as being unconscious, although the effect is the same. A dwarf may fall unconscious when they give in to pain, universally a bad thing, or when recuperating from wounds in a hospital. Finally, hunters have a tendency to fall asleep anywhere, which can cause problems with their happiness. To prevent this behavior, disable hunting from the labors.