A gatehouse is a a small building before the main castle. It also has a portcullis to block off attackers. It also is like a foyer on the inside of it. After the gatehouse is a ditch also known as a moat or a barbican. There is usually two portcullis's in the gatehouse, one after the drawbridge and another after the main part of it.
We got this picture from www.castlexplorer.co.uk