Dig In
For some reason, designers of castles earnestly believed that enemies would try to dig underneath the castle to gain entrance. To combat this, moats were implemented so that any attempt at a tunnel would be instantly flooded. Those who tried to crawl in would drown to death in water and feces.
New Digs
In quite a few castles, the moat didn't surround the castle. Instead, it was located in the center of the first and second castle walls. Those who dug tunnels would not even know how bad things were going to get until it was far too late. They must have really wanted to break in...