A closet (especially in North American English usage) is an enclosed space, with a door, used for storage, particularly that of clothes.
Fitted closets are built into the walls of the house so that they take up no apparent space in the room.
A closet always has space for hanging, where a cupboard may consist only of shelves for folded garments.
"[1] In Elizabethan and Middle English, closet referred to a small private room, an inner sanctum within a far larger house, used for prayer, reading, or study.
"Privy" meaning an outhouse derives from "private", making the connection with the Middle English use of "closet", above.