The gatehouse was the focus of many an attack in the middle ages. Since a castle had to have an entrance to let people in and out, this was the most obvious place to attack. Therefore, gatehouses became the site of some elaborate defensive works.
If the castle had a moat, the gatehouse would have a drawbridge to span it. In time of peace, the drawbridge would be let down in the day, and pulled up at night by means of a chain. During an attack, the drawbridge was closed, and provided an extra covering for the vulnerable gatehouse.
The portcullis was a grid of iron and wood that could drop down in front of the normal gatehouse door to further protect it. It was very heavy, and was raised by a winch system that kept it suspended above the door in normal times. Sometimes, two portcullises would be used. The first one, close to the door, would be dropped first. Then, after the enemies had begun to attack that portcullis, a second one would drop behind them, trapping them and allowing the defenders to finish them off without worrying about reinforcements.