Effective Defense
Castles played critical roles in defense during battles in medieval times. Originally, when castles were built of wood, they were prone to fire. But once stone castles started being built, they became immune to that threat and provided a very stable and strong environment while they were under siege.
Most stone castle walls were approximately 10 feet thick. However, some were up to three times as thick. Especially after motes (dangerous bodies of water surrounding a castle) were invented, castles became difficult targets to destroy, even when trebuchets, mangonels, and battering rams were used.
When a castle would be besieged, those in the castle would survive on the massive amount of stored food and other goods. Most often, there would be more than enough supply available so that they could outlive the length of the battle. Unless the enemy totally destroyed the castle, those inside would survive and eventually win.
In the largest of castles, useable farmland existed so that if the castle was to be besieged, they could still grow their own food to keep the contained population alive, which was sometimes more than a thousand (Sierra). Water was also a critical resource the people needed - most of the time, larger castles had one or more wells.
Some of the weapons used in sieges included the trebuchet, which was essentially a giant slingshot that could propel almost any object up to approximately 1000 feet. A mangonel flung huge rocks to crash the mighty castle walls. The battering ram was a heavy tree trunk with a pointed end, swung like a pendulum at a castle in order to crack the castle walls or tear through the drawbridge. In addition to these heavy weapons, enemy soldiers mostly used arrows in attempt to kill those up on top of the castle. In defense of enemies trying to climb or break into the castle, people at the top of the castles poured hot liquids such as boiling water, oil, or molten lead.
One issue that continued to frustrate and worry castle people during a siege were diggers. Diggers were a nuisance because they would avoid the castle walls by going under them (Sierra). A tunnel under a castle wall caused the wall to sometimes collapse or crumble and let enemies inside. This eventually lead to castle moats (trenches surrounding castles filled with water), which prevented most diggers from making tunnels (Sierra).
Photograph Credit (above): Almourol's Castle (Flickr)

Illustration Credit: Castle under Siege (Hartley and Elliot 74)