Medieval castles were used primarily for defense, but they also provided living quarters and storage for the lord, his family and his estate. Because the lord lived within the castle walls, it was usually a center of government.
Castles, in keeping with their primary role in defense, were designed with several layers of protection. Traditional castles were built on a motte-and-bailey plan, in which a hill, or motte, was surmounted by a walled outer court, or bailey, with a high tower, or keep, in the center. The motte was often surrounded by a wet or dry ditch, which castle defenders crossed using a drawbridge. The large bailey provided plenty of room for a military force or refugees from the surrounding area as well as livestock and provisions. Also located in baileys were outbuildings to support the castle, including kitchens, stables and barracks for soldiers. Castles built to withstand sieges often had additional buildings like smithies and even churches.
The central keep was the home of the lord, his family and his closest retainers. It was a fortified building in its own right, providing a final defensive area if the bailey wall were breached by an enemy. In some castles, the keep was surrounded by its own inner bailey as well.