To understand how earthing works, it's first important to know that our bodies actually generate electricity: You probably remember from high school biology that every cell is made of protons and electrons, and our nervous system basically communicates with those cells by sending electric currents.
The earth also carries its own complex electrical system, and when we make direct contact with it, those two systems interact with each other: The earth carries a very negative charge, and going barefoot (or touching the earth in any way) actually results in a charge exchange.
Preliminary studies show that the electrons that feed into our bodies from the earth may actually function as antioxidants: They neutralize free radicals (which are unpaired positive ions), which, when in excess, can push the body into a state of oxidative stress—something that has been connected with inflammation and many diseases such as cancer.
The current research on the impact of earthing is limited but fascinating nonetheless. One study, for example, found that a group of subjects who were "grounded" to the earth (via a specialized mattress pad) slept better, found their pain reduced, and experienced less stress, thanks to reduced cortisol levels. Another connects earthing to a better immune response.