The short answer
A space qualifies as a courtyard when it is an open area, usually open to the sky, and buildings or walls enclose most of its edge. The more of the edge that is walled in, the more the space reads as a courtyard. A space that is open along most of its edge, such as a paved area beside one house wall, is usually called a patio or yard instead.
Three features that define one
Most descriptions of a courtyard rest on three features. The first is enclosure: buildings or walls surround the space on several sides, so it faces inward. The second is openness: a courtyard is normally open to the sky, which sets it apart from a room or a covered hall. The third is connection: the space is usually reached from the surrounding buildings, through doors, arches or passages.
Where courtyards show up
Courtyards appear in many building traditions. Roman houses had an atrium and a peristyle, and courtyard houses have long been common in the Middle East and Persia. In China, the siheyuan is a home built around a central courtyard. Inner courtyards are a familiar part of older homes in Spain and Latin America. Modern examples include college quads, townhouse courtyards and hotel courtyards with planting and seating.
Edge cases
Some spaces sit between categories. A paved area beside one house wall, with a lawn or fence on the other sides, is usually called a patio. A space between two wings of a building is a courtyard even when it is paved and used like a patio. A roofed space enclosed by walls can count as a covered courtyard, while a large space inside a building, often under glass, is more often called an atrium. A forecourt, the open area in front of a building, is open to the street and fits the definition less well, though people sometimes call it a courtyard.
Planning and local rules
No single legal definition applies everywhere. Planning offices, building codes and property listings may use the word in their own ways. If the label affects a permit or a sale, check the local terms or ask the office directly.
What the label means for a project
If you are planning walls, paving or a roof over the space, the label can matter. An enclosed courtyard may need more attention to drainage and shade than an open patio does, and a roof, especially a glass one, may change how a local office classifies the space. If you are still choosing between the two, the difference between courtyard and patio lays out the main contrasts.