A nightcap is a warm cloth cap worn while sleeping, often with pajamas or a nightgown. They are similar to winter "beanies" worn in cold climates. They were common in northern Europe before central heating was available, when homes were cold at night.
Women's night caps usually consisted of a long piece of cloth wrapped around the head. Men's nightcaps were traditionally pointed, with a long top, usually accompanied by a small ball of some sort, which was used similar to a scarf. It kept the neck warm while not being so long that it could wrap around and become a choking hazard.
In the Tyburn and Newgate days of the British judicial hanging history, the hood used to hide the prisoner’s final agonies was actually a nightcap supplied by the prisoner themselves, if they could afford it. When they had finished their prayers, the hangman simply pulled it down over their face. In some cases, women might choose a bonnet with a veil instead. From around 1850, a white linen hood was provided by the authorities as part of the execution process.
Nightcaps are not often worn in modern times, although they are easily obtained from, for example, better class gentlemen's outfitters. They are often featured in animation and other media as part of a character's pajamas.