A moat is a deep, broad ditch, either dry or filled with water, that is dug and surrounds a castle, fortification, building or town, historically to provide it with a preliminary line of defence. In some places moats evolved into more extensive water defences, including natural or artificial lakes, dams and sluices. In older fortifications, such as hillforts, they are usually referred to simply as ditches, although the function is similar. In later periods, moats or water defences may be largely ornamental. They could also act as a sewer.[ not verified in body]
Some of the earliest evidence of moats has been uncovered around ancient Egyptian castles. One example is at Buhen, a castle excavated in Nubia. Other evidence of ancient moats is found in the ruins of Babylon, and in reliefs from ancient Egypt, Assyria, and other cultures in the region.  
Evidence of early moats around settlements has been discovered in many archaeological sites throughout Southeast Asia, including Noen U-Loke, Ban Non Khrua Chut, Ban Makham Thae and Ban Non Wat. The use of the moats could have been either for defensive or agriculture purposes. 
Moats were excavated around castles and other fortifications as part of the defensive system as an obstacle immediately outside the walls. In suitable locations they might be filled with water. A moat made access to the walls difficult for siege weapons such as siege towers and battering rams, which needed to be brought up against a wall to be effective. A water-filled moat made the practice of mining - digging tunnels under the castles in order to effect a collapse of the defences - very difficult as well. Segmented moats have one dry section and one section filled with water. Dry moats that cut across the narrow part of a spur or peninsula are called neck ditches. Moats separating different elements of a castle, such as the inner and outer wards, are cross ditches.
The word was adapted in Middle English from the Old French motte "mound, hillock" and was first applied to the central mound on which a castle was erected (see Motte and bailey) and then came to be applied to the excavated ring, a ‘dry moat’. The shared derivation implies that the two features were closely related and possibly constructed at the same time.  The term moat is also applied to natural formations reminiscent of the artificial structure and to similar modern architectural features.
With the introduction of siege artillery, a new style of fortification emerged in the 16th century using low walls and projecting strong points called bastions, which was known as the trace italienne. The walls were further protected from infantry attack by wet or dry moats, sometimes in elaborate systems.  When this style of fortification was superseded by lines of polygonal forts in the mid-19th century, moats continued to be used for close protection. 
The Walls of Benin were a combination of ramparts and moats, called Iya, used as a defence of the capital Benin City in present-day Edo State of Nigeria. It was considered the largest man-made structure lengthwise, second only to the Great Wall of China and the largest earthwork in the world. Recent work by Patrick Darling has established it as the largest man-made structure in the world, larger than Sungbo's Eredo, also in Nigeria. It enclosed 6,500 km2 of community lands. Its length was over 16,000 km of earth boundaries. It was estimated that earliest construction began in 800 and continued into the mid-15th century.
The walls are built of a ditch and dike structure, the ditch dug to form an inner moat with the excavated earth used to form the exterior rampart.
The Benin Walls were ravaged by the British in 1897. Scattered pieces of the walls remain in Edo, with material being used by the locals for building purposes. The walls continue to be torn down for real-estate developments.
The Walls of Benin City were the world's largest man-made structure. Fred Pearce wrote in New Scientist:
"They extend for some 16,000 kilometres in all, in a mosaic of more than 500 interconnected settlement boundaries. They cover 6,500 square kilometres and were all dug by the Edo people. In all, they are four times longer than the Great Wall of China, and consumed a hundred times more material than the Great Pyramid of Cheops. They took an estimated 150 million hours of digging to construct, and are perhaps the largest single archaeological phenomenon on the planet."
Japanese castles often have very elaborate moats, with up to three moats laid out in concentric circles around the castle and a host of different patterns engineered around the landscape. The outer moat of a Japanese castle typically protects other support buildings in addition to the castle.
As many Japanese castles have historically been a very central part of their cities, the moats have provided a vital waterway to the city. Even in modern times the moat system of the Tokyo Imperial Palace consists of a very active body of water, hosting everything from rental boats and fishing ponds to restaurants. 
Most modern Japanese castles have moats filled with water, but castles in the feudal period more commonly had 'dry moats' karabori (空堀, 【からぼり】, lit. "empty moat"), a trench. A tatebori (竪堀, 【たてぼり】, lit. "vertical moat") is a dry moat dug into a slope. A unejo tatebori (畝状竪堀, lit. "furrowed shape empty moat") is a series of parallel trenches running up the sides of the excavated mountain, and the earthen wall, which was also called doi (土居, 【どい】, lit. "earth mount"), was an outer wall made of earth dug out from a moat. Even today it is common for mountain Japanese castles to have dry moats. A mizubori (水堀, 【みずぼり】, lit. "water moat") is a moat filled with water.
Moats were also used in the Forbidden City and Xi'an in China; in Vellore in India; Hsinchu in Taiwan; and in Southeast Asia, such as at Angkor Wat in Cambodia; Mandalay in Myanmar and Chiang Mai in Thailand.
The only moated fort ever built in Australia was Fort Lytton in Brisbane. As Brisbane was much more vulnerable to attack than either Sydney or Melbourne a series of coastal defences was built throughout Moreton Bay, Fort Lytton being the largest. Built between 1880 and 1881 in response to fear of a Russian invasion, it is a pentagonal fortress concealed behind grassy embankments and surrounded by a water-filled moat.
Moats were developed independently by North American indigenous people of the Mississippian culture as the outer defence of some fortified villages. The remains of a 16th-century moat are still visible at the Parkin Archeological State Park in eastern Arkansas.
Caerlaverock Castle, a 13th-century castle in southern Scotland
Frozen moat of the walled city of Qufu, China
Beijing ancient city gate and moat
The Daalsesingel, a part of the moat that surrounds the city center of Utrecht, Netherlands
Hikone Castle moat
Forbidden City moat
Landskrona Citadel with mid 15th-century dual moat construction
Dry moats were a key element used in French Classicism and Beaux-Arts architecture dwellings, both as decorative designs and to provide discreet access for service. Excellent examples of these can be found in Newport, Rhode Island at Miramar (mansion) and The Elms, as well as at Carolands, outside of San Francisco, California, and at Union Station in Toronto, Ontario, Canada. Additionally, a dry moat can allow light and fresh air to reach basement workspaces, as for example at the James Farley Post Office in New York City.
Whilst moats are no longer a significant tool of warfare, modern architectural building design continues to use them as a defence against certain modern threats, such as terrorist attacks from car bombs and armoured fighting vehicles. For example, the new location of the Embassy of the United States in London, opened in 2018, includes a moat among its security features - the first moat built in England for more than a century.  Modern moats may also be used for aesthetic or ergonomic purposes.
The Catawba Nuclear Station has a concrete moat around some of the plant. (Other sides of the plant are bordering a lake.) The moat is a part of precautions added to such sites after the September 11, 2001 attacks. 
Moats, rather than fences, separate animals from spectators in many modern zoo installations. Moats were first used in this way by Carl Hagenbeck at his Tierpark in Hamburg, Germany.  The structure, with a vertical outer retaining wall rising direct from the moat, is an extended usage of the ha-ha of English landscape gardening.
Researchers of jumping spiders, which have excellent vision and adaptable tactics,  built water-filled miniature moats, too wide for the spiders to jump across. Some specimens were rewarded for jumping then swimming and others for swimming only. Portia fimbriata from Queensland generally succeeded, for whichever method they were rewarded.  When specimens from two different populations of Portia labiata were set the same task, members of one population determined which method earned them a reward, whilst members of the other continued to use whichever method they tried first and did not try to adapt. 
As a basic method of pest control in bonsai, a moat may be used to restrict access of crawling insects to the bonsai.
- Ha-ha wall
- Moated settlements
- Moot hill (sometimes written as Moat Hill)
- Neck ditch
- Archaeology in Syria Tell Sabi Abyad, archived from the original on March 21, 2007 article on Netherlands National Museum of Antiquities website
- Oredsson, Dag (November 2000). "Moats in Ancient Palestine". Almqvist & Wiksell International. Archived from the original on 2015-09-23.
- McGrath, R., & Boyd, W. (2001). The chronology of the Iron Age'moats' of Northeast Thailand. Antiquity, 75(288)
- Friar, Stephen (2003), The Sutton Companion to Castles, Stroud: Sutton Publishing, p. 214, ISBN 978-0-7509-3994-2
- Lepage, Jean-Denis G. G. (December 21, 2009). French Fortifications, 1715-1815: An Illustrated History. McFarland. ISBN 9780786458073. Archived from the original on January 3, 2016 – via Google Books.
- "Fortress Study Group: Simon Barrass, An Introduction to Artillery Fortification, 2011" (PDF). Archived from the original (PDF) on March 4, 2016.
- "Imperial Palace moats illegally occupied by businesses". Japan Today. August 25, 2006. Archived from the original on October 28, 2006.
- Architecture Correspondent, Jonathan Morrison (2017-12-14). "US embassy: America shows off its Thames fortress". The Times. ISSN 0140-0460. Retrieved 2018-04-26.
- "Nuclear Power Plants to Continue MOX Program". Nuclear Threat Initiative. October 13, 2004. Archived from the original on September 1, 2009.
- Rene S. Ebersole (November 2001). "The New Zoo". Audubon Magazine. National Audubon Society. Archived from the original on 2007-09-06. Retrieved 2007-12-18.
- Urquhart, Conal (June 18, 2004). "Two-mile Gaza moat to foil tunnels to Egypt". The Guardian. London. Retrieved May 12, 2010.
- Glaister, Dan (March 14, 2008). "US city plans moat to keep out migrants". The Guardian. London. Archived from the original on September 2, 2013. Retrieved May 12, 2010.
- Harland, D.P. & Jackson, R.R. (2000). ""Eight-legged cats" and how they see: a review of recent research on jumping spiders (Araneae: Salticidae)" (PDF). Cimbebasia. 16: 231–240. Archived from the original (PDF) on 28 September 2006. Retrieved 5 May 2011.
- Jackson, Robert R.; Chris M. Carter; Michael S. Tarsitano (2001). "Trial-and-error solving of a confinement problem by a jumping spider, Portia fimbriata". Behaviour. Leiden: Koninklijke Brill. 138 (10): 1215–1234. doi: 10.1163/15685390152822184. ISSN 0005-7959. JSTOR 4535886.
- Jackson, Robert R.; Fiona R. Cross; Chris M. Carter (2006). "Geographic Variation in a Spider's Ability to Solve a Confinement Problem by Trial and Error". International Journal of Comparative Psychology. 19: 282–296. Archived from the original on 6 April 2012. Retrieved 8 June 2011.
Media related to Moats at Wikimedia Commons