How were castles in the middle ages defended?

They were usually on top of a hill (sometimes artificial) which meant the attacker had to struggle upwards to reach the castle walls. They were surrounded by a water filled moat which the attackers then had to cross. The main entrance could only be reached across a drawbridge which would be raised during an attack. The entrance was blocked by a heavy metal grill called the portcullis which could be lowered into position. The entrance into the inner courtyard involved passing under holes through which boiling oil could be poured. The alternative means of entry over the wall meant scaling 30 or 40 foot walls on a scaling ladder whilst under fire. Archers would be positioned in towers firing arrows through slits in the stonework at the attackers. Inside the walls was an inner fortress called the Donjon which required a second attack whilst being a target for the archers on all sides (in towers and on walls). The commonest method of attack was the seige where the attackers surrounded the castle and hoped the defenders would run out of food or water. For this reason some castles were sited by the sea so that supplies could come in by boat at high tide.