How does my device's accelerometer know how far I ran on the treadmill?

The home screen and tutorial opening for the "Zombies, Run!" app
The home screen and tutorial opening for the "Zombies, Run!" app
Screencaps by HowStuffWorks staff

I'm exhausted, but I have to keep running. I have to warn the Brunswick settlement that a horde of zombies is on its way to attack them. The song I'm listening to ends, I hear a crackle over the comms channel, and then Sam relays the bad news: The zombies are closer to the settlement than I am, and I'm going to have to pick up the pace to get there in time to deliver the warning. With human lives at stake, I have no choice. I have to find a burst of speed.

Never mind that all of this happens in the safety of my home, on my treadmill. The running and resultant exhaustion are very real. And the dire survival scenario? That's courtesy of "Zombies, Run!" -- an app designed to gamify running and walking workouts by layering an apocalyptic storyline over your training. I love being able to lose myself in these fictional missions while I run, but the reality is that I'm training for a half marathon. I need to achieve certain goals in my running workouts to ensure I'm prepared for my upcoming event. I need to know how far I've run, and at what pace.

There are abundant running apps for iOS and Android phones to track your distance and time for you. Almost all of them have GPS tracking built in, which nearly all runners and developers will agree is the most accurate way to monitor your stats. But sometimes, schedules and location make it impossible to run outside, and then your app has to rely on your device's accelerometer to track your pace and distance. But how can it do that, and are those measurements accurate?