A castle wall was designed to act as a first line of defence against attack.
Early castles were built on a mound, or motte. The single building on the mound was called a donjon (because it was a Norman French introduction to England) but it soon became known as a keep.
A single wall was often built in early Medieval times. leading out from the keep and making a kind of horseshoe shape. This gave the castle and its staff more room to keep horses and more building room for people. Supplies to outlast a siege could also be kept there.
The wall was called a curtain wall. It often had a number of towers along it. Each tower protruded from the wall so that soldiers could fire on those trying to scale the walls.
By the time of Edward I, a double curtain wall was being built. The outside wall was to keep out attackers, but if, by chance, they got over the wall, they would find yet another wall. The space between the walls was called the outer bailey or outer ward, while the inside area was the inner bailey or inner ward. The Tower of London shows this pattern superbly. The space between the walls was a killing ground because archers on both walls could fire down on to the attackers trapped between the walls.
Very few double-walled castles were ever successfully attacked.