Moat
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.

Historical use
Ancient
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.

Medieval
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 (lit. '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.

Later western fortification
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.

Africa
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."

Asia
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 Fort  in India; Hsinchu in Taiwan; and in Southeast Asia, such as at Angkor Wat in Cambodia; Mandalay in Myanmar and Chiang Mai in Thailand.

Australia
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.

North America
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.
The Maya people also used moats, for example in the city of Becan.
European colonists in the Americas often built dry ditches surrounding forts built to protect important landmarks, harbours or cities (e.g. Fort Jay on Governors Island in New York Harbor).

Photo gallery
Modern usage
Architectural usage
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.

Anti-terrorist moats
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 improvised 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.

Safety moats
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.

Border defence moats
In 2004 plans were suggested for a two-mile moat across the southern border of the Gaza Strip to prevent tunnelling from Egyptian territory to the border town of Rafah.In 2008 city officials in Yuma, Arizona planned to dig out a two-mile stretch of a 180-hectare (440-acre) wetland known as Hunters Hole to control immigrants coming from Mexico.

Pest control moats
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.

See also
Drawbridge
Gracht
Ha-ha wall
Moated settlements
Moot hill (sometimes written as Moat Hill)
Neck ditch

References
External links
 Media related to Moats at Wikimedia Commons