A castle could have been used as a home for Kings and Lords but they were mostly used as a defense posts for a town or a city, to keep the castle defended was hard work, but there were ways.
One way was to build an outer wall around the outside of the castle. This meant that the attackers would have to get through the wall and then through to the castle, which might even have a moat, possibly filled with water but usually not.
Any entrance to the castle was a weak point there was usually only one entrance which would be called a barbican. As it was the weakest point it was heavily defended, such defenses could be:
The Drawbridge:
This was raised by a series of chains and winches which were housed in the room above, called the gatehouse.
A Portcullis:
This was a heavy gate which would fall down from a gap in the roof, just after the entrance part, and the enemy would be trapped inside the small space or they wouldn't be able to get in, there would usually be murder holes in this part (read Murder Holes for more information).
Arrow slits:
Narrow vertical windows where castle defenders could fire arrows down at the advancing enemy, but the enemy couldn't fire back at the bowman.
Murder Holes:
These were holes in the roof of the barbican and sometimes towers, where rocks, hot sand, molten lead, boiling tar, boiling water, boiling oil and other missiles which could be thrown, for example there could be a rotting substance such as dung or dead bodies. These items could be thrown onto the enemy inside the barbican or by the side of the towers when under siege.
Spikes:
The Garrison of the castle would throw spiky metal caltrops, which when stuck in the ground would face up and hurt horses and foot soldiers.
Other defences could be the towers especially the circular towers as they had a 360 degree view of their surroundings and in battle soldiers could hide behind the taller walls and attack from the lower walls.
So that's the medieval defence, hope you enjoyed reading it. Feel free to post a comment below.