A ditch in military engineering is an obstacle, designed to slow down or break up an attacking force, while a trench is intended to provide cover to the defenders. In military fortifications the side of a ditch (or gorge) farthest from the enemy and closest to the next line of defence is known as the scarp while the side of a ditch closest to the enemy is known as the counterscarp.
In early fortifications, ditches were often used in combination with ramparts to slow down the enemy whilst defensive fire could be brought to bear from the relative protection afforded by the rampart and possibly the palisade. In medieval fortification, a ditch was often constructed in front of a defensive wall to hinder mining and escalade activities from an attacker. When filled with water, such a defensive ditch is called a moat. However, moats may also be dry.
Later star forts designed by military engineers like Vauban, comprised elaborate networks of ditches and parapets, carefully calculated so that the soil for the raised earthworks was provided, as nearly as possible, entirely by the excavations whilst also maximising defensive firepower.
Today ditches are obsolescent as an anti-personnel obstacle, but are still often used as anti-vehicle obstacles (see also berm).
A fence concealed in a ditch is called a ha-ha.