Mining was a siege method used in ancient China from at least the Warring States (481–221 BC) period forward. When enemies attempted to dig tunnels under walls for mining or entry into the city, the defenders used large bellows (the type the Chinese commonly used in heating up the blast furnace for smelting cast iron) to pump smoke into the tunnels in order to suffocate the intruders.
A tactic related to mining is sapping the wall, where engineers would dig at the base of a wall with crowbars and picks. Peter of les Vaux-de-Cernay recounts how at the battle of Carcassonne, during the Albigensian Crusade, "after the top of the wall had been somewhat weakened by bombardment from petraries, our engineers succeeded with great difficulty in bringing a four-wheeled wagon, covered in oxhides, close to the wall, from which they set to work to sap the wall" (les Vaux-de-Cernay, 53).
As in the siege of Carcassonne, defenders worked to prevent sapping by dumping anything they had down on attackers who tried to dig under the wall. Successful sapping usually ended the battle since either the defenders would no longer be able to defend and surrender, or the attackers would simply charge in and engage the defenders in close combat.
There were several methods to resist under mining. Often the siting of a castle could be such as to make mining difficult. The walls of a castle could be constructed either on solid rock or on sandy or water logged land making it difficult to dig mines. A very deep ditch or moat could be constructed in front of the walls, as was done at Pembroke Castle, or even artificial lakes as was done at Kenilworth Castle. This makes it more difficult to dig a mine and even if a breach is made the ditch or moat makes exploiting the breach difficult. The defenders could also dig counter mines. From these they could then either dig into the attackers tunnels and sortie into them to either kill the miners or to set fire to the pit-props to collapse the attackers tunnel. Alternatively they could under mine the attackers tunnels and create a camouflet to collapse the attacker's tunnels. Finally if the walls were breached they could either place obstacles in the breach for example a chevaux de frise to hinder a forlorn hope, or construct a coupure. The great concentric ringed fortresses like Beaumaris Castle on Anglesey were designed in such a way that the inner walls were ready built coupures so that if an attacker succeeded in breaching the outer walls would have left them in a killing field between the lower outer walls and the higher inner walls.
A more famous instance occurred during the Siege of Petersburg, Union troops dug a tunnel under the Confederate lines at Elliott's Salient and packed its end with vast amounts of gunpowder. When set off, the resulting explosion killed about 300 soldiers. It might have been decisive if not for the faulty Union tactic of storming into, rather than around, the resulting crater, allowing the defenders to shoot down onto attackers unable to climb the steep crater sides. The combat was accordingly known as the Battle of the Crater. (The horror of this engagement was portrayed in the Charles Frazier novel and subsequent Anthony Minghella movie Cold Mountain.)
A notable example was the Battle of Messines, when 450 tonnes of high explosive were placed in 21 mines after about two years of sapping. Approximately 10,000 German troops were killed when 19 of the mines were simultaneously detonated. One of the explosive caches exploded years later. The 21st cache was never found and there are still several tonnes of high explosive buried somewhere in the Belgian countryside.
By World War II troop movements were too fluid, and tunneling too slow, for mining to be worth the investment of effort.