Tunnels are useful for going under things you cannot move, or things that are too expensive to remove, like large mountains for example. You can't build a bridge over cities, stations or industries, but you can tunnel under them.
They can also be used in Junctionarys as vehicles can pass through them without slowing down, unlike with some Bridges.
You can dig tunnels for roads and railways. Bear in mind that you can't change between road and rail in a tunnel without rebuilding the tunnel (although you can change between different types of rail).
- Click on railway build button or road build button on the menu bar. Once clicked the railway construction or road construction toolbar pops up.
The screenshots in this tutorial show railway tunnels, but constructing a road tunnel uses the same steps.
- Move the cursor around the map to find a good spot for a tunnel. You can't dig a tunnel on a flat land, only on a hillside.
- Move the cursor over a slope and you can see the path of the tunnel you are about to build highlighted in white.
To build the tunnel, just click on the sloped tile.
Advanced tunnel building
If you want to tunnel somewhere that does not slope in the right place or direction, you will have to either raise or lower land to correct it and allow a tunnel to be built.
If there is a slope in an odd direction at the end of the tunnel, it will be automatically lowered so that the tunnel can be dug. However, you can't start digging the tunnel at such a slope; you must terraform it first.
Sometimes, the odd directed slope can't be lowered automatically because of obstacles on surrounding tiles. You will see an error window saying so.
Raise the land manually, so the tunnel end tile is a flat slope.
- Tunnels cannot cross each other underground - you will be warned about it if you try. Also, you will be prevented from excavating the landscape from above if there is a tunnel underneath. However, there is a cheat that allows you to build crossing tunnels. With the cheat on, trains can cross other trains, also.
- You cannot place signals inside railway tunnels so you may not have more than one train in a tunnel at once. Very long tunnels can therefore slow down your rail networks.
- Every tunnel/bridge piece counts as 4 regular rail/road/canal pieces, making them more expensive to maintain for the same distance. 
- The air drag in rail tunnels is twice the amount that it is outside. (src/train.h:GetAirDragArea)