The basic principal of castle defense was to maximize the danger and exposure of any attackers while minimizing the same for defenders. A well-designed castle could be defended effectively by a small force and hold out for a long period. A stout defense allowed well-supplied defenders to hold out until the besiegers could be driven away by a relief force or until the attacker was forced to fall back by lack of supplies, disease, or losses.
Keep
The keep was a small castle often found within a large castle complex. This was a fortified building that often served as the castle lord's residence. If the outer walls fell, the defenders could withdraw into the keep for a final defense. In the case of many castles, the complex began with the keep, which was the original fortification on the site. Over time, the complex might have been expanded to include an outer wall and towers as a first line of defense for the keep.
Walls
Stone walls were fireproof and protection against arrows and other missiles. An enemy could not climb sheer walls without equipment such as ladders or siege towers. Defenders on top of the walls could shoot down or throw objects down against attackers. Attackers wholly exposed in the open and shooting up were at a great disadvantage against defenders largely protected and shooting down. The strength and protection value of castle walls was increased where possible by building on cliffs or other elevations. Gates and doors in castle walls were minimized and given heavy protection.
Towers
At the corners of and perhaps at intervals along a long wall, towers were placed as strong points. Towers extended out beyond the vertical plane of the wall face, allowing defenders in a tower to shoot along the face. From a corner tower, defenders could shoot along two different wall faces. A gate might be protected by towers on each side. Some castles began as simple towers and evolved into a greater complex of walls, an inner keep, and additional towers.
Battlements
Walls and towers were often improved to provide greater protection for defenders. A platform behind the top of the wall allowed defenders to stand and fight. Gaps were built into the upper wall so defenders could shoot out or fight while partially covered. These gaps might have wooden shutters for additional protection. Thin firing slits might be placed in the upper walls from which archers could shoot while almost completely protected.
During an assault, covered wooden platforms (called hourds) were extended out from the top of the walls or from towers. These allowed defenders to shoot directly down on enemies below the walls, or drop stones or boiling liquids on them, while being protected. Hides on top of the hourds were kept wet to prevent fire. Stone versions of hourds, called machicolations, might be built over gates or other key points.
Ditches, Moats, and Drawbridges
To accentuate the height advantage of the walls, a ditch might be dug at their base, completely around the castle. Where possible, this ditch was filled with water to form a moat. Both ditches and moats made direct assaults against walls more difficult. Armored men risked drowning if they fell into even relatively shallow water. Moats made undermining a castle's walls difficult because of the risk of the mine collapsing during construction and drowning the miners. In some cases, attackers had to first drain the moat before moving forward with an assault. Then the ditch had to be filled in places to allow siege towers or ladders to go up against the wall.
Drawbridges across a moat or ditch allowed the castle occupants to come and go when necessary. In time of danger, the drawbridge was raised, reestablishing the ditch and sealing the walls. Bridges were raised by a mechanism within the castle that was protected from the attackers.
Portcullis
A portcullis was a strong grating that slid down the walls of the castle gate passageway to block the entrance. The gate of a castle was inside a gatehouse, which was a strong point in the castle defense. The passageway of the gate might be through a tunnel in the gatehouse. The tunnel was blocked by one or more portcullises, in the middle or at the ends. The winding mechanism that raised the portcullis was in the top of the gatehouse and heavily guarded. The portcullis itself was usually a grating of heavy timbers or iron. Defenders and attackers could both shoot or stab through the grating.
Barbican
A strong castle had both an outer gate and inner gate. Between the two was an open area called the barbican. This was surrounded by walls and designed to be a trap for any attackers who got through the outside gate. Once inside the barbican, attackers could only go back out the outer gate or fight their way through the inner gate. In the meantime they would be targets for arrows and other missiles in the open.
Defenders
A relatively small number of men could guard a castle in peacetime. At night any drawbridge was raised and the portcullis was lowered, effectively locking the door. Under threat of an assault, a much larger force was needed to defend a castle.
Competent archers and crossbowmen were needed to shoot from the walls and towers at attackers making an assault or just preparing for one by attempting to drain the moat or fill the ditch. Each attacking casualty lowered the morale and fighting power of the attackers. Heavy losses from missile fire could cause the attackers to break off.
If the attackers managed to actually close for hand-to-hand fighting, a strong fighting force of swordsmen was needed to hold them off. Men were needed to throw down rocks or pour hot liquids from the hourds. Men were needed to make repairs to damaged wall sections or put out fires started by flaming missiles. An aggressive defense looked for opportunities to sortie out from the castle and raid the besieging army. A quick raid that burned a siege tower or trebuchet under construction delayed an assault and lowered the morale of the attackers.
In times of emergency, local peasants were enlisted to help with the defense. Although untrained as soldiers and not skilled usually with the bow or sword, they could help with many of the other tasks.