The current war between Israel and Hamas was only partly about the persistent rocket attacks against Israel launched from Gaza. Israel made it clear, soon after the fighting broke out in early July, that one of its primary objectives was to find and destroy all the tunnels Hamas had dug into Israel over the last few years. This could only be accomplished if Israeli troops were inside Gaza and able to search for the places where the tunnels started. Hamas boasted about how it had lots of these tunnels and planned to use them to get terrorists into Israel to capture or kill Israelis. This is not a new problem. The Palestinians in Gaza have been building tunnels (mainly into Egypt for smuggling) since the 1980s. The Egyptians long tolerated this because the local Egyptian police and soldiers got bribed and that kept everyone happy. But tunnels into Israel were another matter, because these were not for smuggling but for killing or kidnapping Israelis. No bribes involved here, just murder and abduction (for ransom).
When Hamas took control of Gaza in 2007 by defeating (militarily, and at the ballot box) the more moderate Fatah, they turned Gaza into a police state. Then they took charge of the economy by controlling what went through smuggling tunnels, and what people paid for it. While Hamas complains about the Israeli blockade, which is in place because Hamas refuses to stop demanding that Israel be destroyed, and bringing weapons (especially long range rockets) into Gaza to make that happen, they would go bankrupt if the blockade were lifted and the tunnel income disappeared.
These smuggling operations are so lucrative that Hamas deems them legal enterprises, and charges a large (several thousand dollars) fee for anyone who wants to build and operate a tunnel. In addition, armed Hamas revenue collectors stand at the Gaza entrance for each tunnel, demanding a payment for everything coming out of Egypt, or going there. Exactly how many tunnels there are is something of a mystery. Given that the Gaza border under Egyptian control is only about 14 kilometers long, it would appear that the actual number of operating tunnels is rarely more than a hundred. Israeli sources frequently say there are 300 or more. In the last year Egypt has destroyed most of the tunnels into Egypt because Gaza has become a sanctuary for a growing number of anti-Egypt Islamic terrorists.
Israel and Egypt often cooperated to identify the tunnels used to move missiles and other weapons into Gaza. Egypt sometimes passed information on to Israel, and then these tunnels were shut down with an Israeli air strike. Sometimes using a ground penetrating bomb. Destroyed tunnels were not gone forever and were often repaired and soon back in action. But most of the tunnels are left alone so consumer goods can get into Gaza and the Egyptian border force could continue to extort bribes from the tunnel operators. Egypt was usually cooperative in shutting down the weapons shipments, because Hamas also sheltered Islamic terrorists who focused their attacks on Egyptian targets.
The Gaza border area is a desert, and if you dig down 6-20 meters, you'll find hard sand that can be excavated at the rate of 15 meters a day. Thus to build a tunnel you need cooperation from building owners on both sides of the border. They expect to get paid, usually a flat fee to start work, then monthly "rent", or even a percentage of revenue from people and goods going through the tunnel.
The Egypt tunnels tend to be 500-600 meters long. So including digging down on each end, it's going to take you 5-6 weeks to complete your tunnel. If you have a few experienced (and highly paid) people working with you, the whole project will cost you $25,000 or more. That's a lot of money in Gaza. But the potential profits are enormous. Currently, moving a person through a tunnel costs several hundred dollars, or more. A sack full of goods, or a 20 liter can of fuel, costs several times its value to move through the tunnel.
The downside is that most tunnels are just wide enough (about a meter, and a little less tall) for a man to crawl. The air is foul and the risk of collapse is constant. Few tunnels are built with bracing, to prevent, or mitigate a collapse. It is believed that hundreds of Palestinians are dead and buried under the border, as a result of collapsed tunnels. When the Israelis ran the place (until they left in 2005 as a peace gesture that backfired), they got pretty good at finding, and destroying, tunnels. The Egyptians, who now guard the border alone are nowhere near as good, and they can be bribed. But even today, a tunnel rarely lasts more than a few months, and someone usually dies as it collapses and goes out of service. Thus the high fees for getting stuff through. The men who move goods through the tunnels are highly paid, but are poor insurance risks.
Over the years Hamas has learned how to dig tunnels that are virtually undetectable on the Israeli side. This means going deep enough to avoid detection by ground penetrating radar or acoustic sensors. This makes it more expensive and time consuming to build tunnels but Hamas has diverted much foreign aid (cash and building materials) to the tunnel effort. A lot of the concrete and other building materials allowed into Gaza went to building tunnels.
By 2014 Israel knew of the new, deeper and more complex Hamas tunnels into Israel but had found only four of them since 2012. In March Israeli troops found one that was 1,800 meters long and extended 300 meters into Israel. Hamas dismissed this find as a tunnel that had been abandoned because of a partial collapse. But the Israelis said the tunnel had been worked on recently and equipment, like generators, was found in it. The tunnel was lined with reinforcing concrete and was 9-20 meters (30-63 feet) underground. Three of these tunnels were near the town of Khan Younis and apparently part of a plan to kidnap Israelis for use in trades (for prisoner or whatever) with Israel.
Israeli intelligence knew Hamas leaders were discussing a much larger tunnel program, involving dozens of tunnels and suspected that dozens of them were already built or nearing completion by mid-2014. Most of the completed one had no exits in Israel, yet. Available monitoring equipment was slow and often ineffective if there was no one actively working on the tunnel below or if there was no exit (yet) on the Israeli side. Another problem was that Hamas had, by trial and error, discovered the limitations or blind spots of Israeli tunnel detection gear and techniques.
The Hamas tunnels already built and “stockpiled” could only be detected inside Gaza, where their entrances were. These were also hidden, at least from aerial observation. Israeli intelligence had discovered possible tunnel entrances by detecting the Hamas activity around the suspected entrances (entering and leaving, removing dirt). Hamas tried to hide this activity and Israel knew this meant they probably succeeded in some cases. Thus before the Israeli troops went into Gaza recently, commanders had lots of information of where to look. By the end of July the Israelis had found 46 entrances to 14 tunnels. They also discovered that many of the tunnels had numerous branches inside Gaza and were meant to be used to move Hamas gunmen and suicide bombers around if the Israelis invaded. These Hamas men could then come to the surface behind Israeli troops and attack. This was one reason why there were so many Israeli casualties this time around (compared to the 2009 invasion).
Israeli combat engineers had been trained to destroy the tunnels, which was not easy because Hamas had booby-trapped some of them. Israel now suspects there are over fifty of these tunnels and stayed inside Gaza until they felt they has found all of them, and collected information on how they are built and how they can be detected from the ground or air. If Israel knows where a tunnel is, before they destroy it they can run some tests with their sensors and that knowledge will make it more difficult for Hamas to build new tunnels.