A moat is a body of water around a castle or town to keep out bad people. At first, moats were simple and used only for protection. Later on, moats became more complex and decorative.
Moats are deep, wide ditches filled with water. They were usually built near sources of water that flowed into the moats, filling them with water. The moats were filled with water for a few reasons. It made enemies swimming across the moat easy targets. It also made it impossible for enemies to dig underneath the castle walls, which was a common method of attack. It also prevented fires from destroying the castle. 
The word moat comes from the French word motte, which means hill. Moats were first used in the Medieval period, from 1066 to 1154. Castles were built on the top of high hills. The area at the bottom of the hill was eventually called the moat.