The practice of gating and walling of castles and cities
Gated and walled cities can be traced back to ancient times. Jericho, the world's oldest city was a fortified and walled city. And then there were castles surrounded by walls. Walls in those days were needed for protection against enemies and bandits and to keep out unwanted persons.
Defensive mechanisms and structures such as curtain walls, towers, moats, gatehouses, barbicans, portcullises, heavy wooden doors, murder holes, steep inclines,etc were in fact all formidable uniquely designed obstacles to give the defenders every pos- sible advantages over the attackers - to slow down or stop the enemy advance, to prevent them from smashing through walls, to protect the inhabitants, the castle or city. In many instances these obstacles were very effective making a castle surrender a complicated and difficult task.
To overcome these obstacles or crash all resistance in order to have almost every advantage over the defenders and to capture the castle or walled city, attackers on the other side of the walls needed carefully planned techniques and sophisticated weapons. They just needed to find or cause a weakness in the defenders "defence system" and exploit it.
When a castle or city could not be taken quickly by direct assault the attackers laid siege to these fortifications. They surrounded the castle or city then used several siege techniques (cut off supplies to the castle, etc) and a variety of siege warfare weapons (siege towers, catapults, mangonels, etc) to force it to surrender. This could take weeks, months or even years to accomplish. Many sieges failed others not.
1) Castles
The middle ages - In the days of feudalism stone castles were enclosed in solid tall outer walls and in some cases inner and outer walls (curtain walls) with high towers, battlements and arrow loops. And the entire wall or walls were often surrounded by a broad, deep water filled moat. In many instances castles were built on high ground where they had a good view of the surrounding countryside.
In a great tower (inner stronghold, the keep or donjon) the best fortified part of the castle, lived the lord and his family.The area between the keep and the curtain walls was called the bailey (courtyard). Castles were originally designed and built as fortified residences, but they also served as symbols of might, power, wealth, status, authority and prestige. The only way to cross a moat and reach the castle was via the drawbridge that could be lowered or raised by means of winches and chains from the room above the gatehouse.
If someone was able to cross the bridge he could be stopped at the gatehouse, a fortified structure built into the wall over the main entrance. The gatehouse normally included defensive features: a heavy wooden door, murder holes and a portcullis - this heavy timber or metal grill (portcullis) could be raised or lowered in front of the wooden door to block the entrance especially when the castle came under attack. Sometimes two to four portcullises would be used to protect the entrance. Gatehouses were often defended by barbicans - a fortified structure leading to the gatehouse. See also 2) Walled Cities.
2) Walled cities
In the middle ages people used to build defensive walls around their cities as protection against foreign invaders and bandits. Massive towers or bastions and main and lesser city gates were incorporated into the walls. City gates were traditionally built to provide a point of controlled access to and departure from a walled city for people, vehicles, goods and animals. (Wikipedia). The gatehouses normally included: