The grounding system provides two different safety functions:
- Provide a path for lightning and other "natural" electricity to the physical ground (i.e., the dirt). Otherwise this electricity could zap your equipment.
- Provide a path for a short circuit (e.g., hot wire to a metal appliance cabinet) to go back to the breaker panel so that the breaker will trip.
In order to take care of the path to physical ground, you install a wire from the main panel goes to some combination of:
- 1 or 2 ground rods, and if there are 2 ground rods then they must be several feet apart
- an Ufer ground (basically a ground rod in concrete, so installed when the house is built)
- metal water pipe
Which ones you use will vary depending on local rules. Almost always 2 ground rods will do the trick. But it varies somewhat by jurisdiction and sometimes even by inspector.
When there are separate buildings, each building will normally have its own ground rods/Ufer ground/water pipe ground.
In addition, there is a connected series of ground wires from all receptacles/devices and subpanels back to the main panel. Many older homes do not have these wires everywhere, but they can be added where needed. Unlike regular wires (hot and neutral), while these ground wires are normally run as part of the same cables as regular wires or in the same conduit as regular wires (or in some cases metal conduit itself is in place of a ground wire), you are allowed to add separate ground wires in order to add grounding where there was none before.
An important piece of this system is that even if you have multiple buildings and multiple breaker panels, ground and neutral are always and only connected together in the main panel, which is sometimes the same box that has the meter ("meter main") or is the first panel after the meter.
Note however that ground rods (or Ufer or water pipe) only apply to a panel. If you have a single circuit feeding an outbuilding then you have no place to properly install a wire for ground rods and, as I understand it, you are exempt. However, if you install a subpanel in that same building then it does need ground rods, etc.
But there is one other option for grounding typical 15A and 20A 120V circuits: GFCI.
A ground-fault circuit interrupter, or GFCI, does not directly use "ground" in the ways described above. A GFCI/receptacle will have a ground screw but the GFCI function works whether that ground screw is connected to a ground wire or not. A GFCI works by checking for a balance between hot and neutral. If there is an imbalance then there is current going somewhere: ground, a person or someplace else it shouldn't be going. Since any current going to ground would in fact trip a GFCI, it is allowed as a substitute for a ground wire. It must be labelled properly but it will provide the desired safety that a proper ground wire would provide and in fact provides additional safety because it operates very quickly and at very low levels.
In fact, garage receptacles are now required to have GFCI. So by installing GFCI protection, either at the breaker or at the first receptacle in the garage, you provide safety that is comparable to, and in some ways better than, what a ground wire would provide, and you also get your garage closer to compliance with current code. GFCI has not always been required for garage receptacles, so you may not be required to add it, assuming everything else was done properly at the time of installation, but it is an easy fix for the grounding problem.
For those who may be wondering why ground rods without also having a ground wire back to the main panel is not a good idea, the problem is that dirt is a very poor conductor. A short-circuit that would normally, with a proper ground wire, cause a very quick breaker trip, may instead not trip the breaker because the electricity traveling through the ground wire/rod will have to overcome high resistance which means less current will flow to the breaker and so the breaker may not know there is an actual short circuit. That can lead to all sorts of problems and be very dangerous. GFCI solves the problem because it trips at very low levels - 6 milliamps vs. 20 amps or more.