Tunneling is a quantum mechanical effect. A tunneling current occurs when electrons move through a barrier that they classically shouldn't be able to move through. In classical terms, if you don't have enough energy to move "over" a barrier, you won't. However, in the quantum mechanical world, electrons have wavelike properties. These waves don’t end abruptly at a wall or barrier, but taper off quickly. If the barrier is thin enough, the probability function may extend into the next region, through the barrier! Because of the small probability of an electron being on the other side of the barrier, given enough electrons, some will indeed move through and appear on the other side. When an electron moves through the barrier in this fashion, it is called tunneling.
Quantum mechanics tells us that electrons have both wave and particle-like properties. Tunneling is an effect of the wavelike nature.
Schematic of electron wavefunction
The top image shows us that when an electron (the wave) hits a barrier, the wave doesn't abruptly end, but tapers off very quickly - exponentially. For a thick barrier, the wave doesn't get past.
The bottom image shows the scenario if the barrier is quite thin (about a nanometer). Part of the wave does get through and therefore some electrons may appear on the other side of the barrier.
Because of the sharp decay of the probability function through the barrier, the number of electrons that will actually tunnel is very dependent upon the thickness of the barrier. The current through the barrier drops off exponentially with the barrier thickness.
To extend this description to the STM: The starting point of the electron is either the tip or sample, depending on the setup of the instrument. The barrier is the gap (air, vacuum, liquid), and the second region is the other side, i.e. tip or sample, depending on the experimental setup. By monitoring the current through the gap, we have very good control of the tip-sample distance.
Feedback loop and electron tunneling for scanning tunneling microscopy (STM)