To ground a subpanel in a detached building, pull 4 conductors and separate the grounded and grounding bus. This part is covered by National Electrical Code article 250.32, although it is one of the longest and most complicated portions in the whole grounding chapter, and it may be quite difficult.
According to the National Electrical Code, both subpanels and main panels must follow specific standards (NEC). A detached structure with a sub-panel requires its own ground rod, whether it is fed by three or four wires.

How to Ground a Subpanel in a Detached Building
Pull four conductors: two ungrounded (hot), one grounded (neutral), and one grounding. At the sub-panel, the grounded (neutral) and grounding buses must be disconnected. Unless your local code permits it, there is no need for a GFCI breaker on the main panel. At the second structure, a grounding electrode system is necessary.

Conditions that Affect Grounding a Subpanel
If any of the grounding electrodes listed in 250.52(A) are present at the building or structure being served, they must be connected together to form a grounding electrode system.
If there is no grounding electrode, one must be placed. A building or structure that is served by a single branch circuit, either individual or multiwire, that contains an equipment grounding conductor is exempt from the grounding electrode requirement in 250.32(A).
Reason Behind the Separation of Grounds and Neutrals
Current can travel on both ground and neutral back to the main panel when ground and neutral are linked. If the load becomes imbalanced and ground and neutral are bonded, current will flow through everything bonded to the sub-panel (enclosure, ground wire, pipe, and so on) and back to the main panel which is hazardous.
Specific Considerations
A feeder or branch circuit servicing a separate building or structure must normally have an equipment grounding conductor, according to NEC Article 250.32(B)(1). The EGC might be a wire or any of the wiring methods specified in section 250.118 that qualifies as an EGC. If it is wire, it must be sized according to 250.122.
Exception number one enables the grounded conductor of feeders or branch circuits to be utilized for grounding at different buildings or structures. An EGC is not included in the circuit that powers the distinct building. Second, no continuous metallic routes connect the feeder source to the destination at the building.
The Grounding System for a Separate Structure
There is no need for a ground wire in the cable that feeds electricity to the panel at the separate structure. A GES, or Grounding Electrode System, must be installed at the subpanel’s distinct structure. The remote panel’s grounding electrode conductors must be sized in accordance with the NEC 250.66 Table.
Because the detached building has a ground system, the ground and neutral must be linked together at the panel. According to article 225.31 of the NEC, If there are more than six circuit breakers in the subpanel, the main breaker must be placed.
Ground Rod for a Subpanel
All detached building sub-panels require at least one, and occasionally two, grounding electrodes, also known as ground rods. The soil conditions and the local code requirements will determine whether or not you need two.
Grounding Rod for Subpanels in the Same Building
In all cases, a ground wire must be routed from the main panel to the subpanel. It doesn’t matter how far you’re running it, whether to an outbuilding or up a space elevator. You must run a ground or you will be out of the code.
Frequently Asked Questions
How high off the ground does a sub-panel have to be?
All electrical panels should have at least 36 inches of room in front of the panel, 30 inches of space across the face of the panel, and 78 inches of clearance from the top edge of the panel to the floor.
Conclusion
Separate buildings or structures served by feeders or branch circuits must follow specific grounding and bonding regulations. A grounding electrode is normally necessary unless the building or structure is powered by a single branch circuit and fits the conditions of 250.32 (A).
One part says “There is no need for a ground wire in the cable that feeds electricity to the panel at the separate structure. A GES, or Grounding Electrode System, must be installed at the subpanel’s distinct structure. The remote panel’s grounding electrode conductors must be sized in accordance with the NEC 250.66 Table.”
But another part says “In all cases, a ground wire must be routed from the main panel to the subpanel. It doesn’t matter how far you’re running it, whether to an outbuilding or up a space elevator. You must run a ground or you will be out of the code.”
Aren’t these saying the opposite of each other? What am I missing?
I think they are saying you don’t need to run a ground wire from one structure to the next, but you DO need to install a grounding system at the remote structure and create a way to safely ground that building and it’s electrical equipment.
But I’m not an electrician, just pointing out the subtleties of the nomenclature, which gets pretty weird. If you aren’t sure what you are doing, hire an electrician. They are cheap compared to the alternative.
Where it says “in all cases etc…”, it is for when the sub panel is in the same building. For a sub panel in a detached building you do not need to run a ground wire. Grounding rod is required and must be bonded with the neutral
I agree, it is contradictory.
There is no need for a ground wire in the cable that feeds electricity to the panel at the separate structure.
It doesn’t matter how far you’re running it, whether to an outbuilding or up a space elevator.
Apparently a separate structure and an outbuilding mean something different to the author.
It is surely confusing. From a residential perspective, the “separate structure” is the service entrance from the utility meter to the home’s main panel disconnect. The “distinct structure” is the subpanel at that same home’s accessory building. Therefore, you don’t have a ground wire to the meter since the main panel/disconnect is bonded, but you need the ground in all subpanels everywhere else supplied by that main panel/disconnect.