What is the Definition of a Legal Bedroom?

This question occasionally pops up and surprisingly, there seem to be a couple of answers. Zillow user unbelieve asks in Zillow Advice:

“Realtor said I don’t need a closet to call a room a bedroom. Will this kill a deal? Is it true”

What is the code in your state/area? Some areas say you need a door and closet and others say you must have a door, closet and window. Let us know!