Medieval castles frequently used moats as a vital form of defense against an attack. A moat was a large ditch dug all around the castle in order to act as a barrier between an approaching enemy and the castle walls.
Most moats were then filled with water to make them impassable for an enemy.
In some cases, the moats were set up with wooden stakes to make it impossible for the enemy to pass it without significant delays and hazards. The primary purpose of the moat was to bar an enemy from having direct and easy access to castle walls.
A secondary purpose was to simply delay an enemy so as to give castle defenders sufficient time to devise a strategy.