Google Maps Google Maps on the iPhone. Google

Last Saturday, as I was driving out of Brooklyn, Google Maps alerted me that there was traffic on the highway and that it had found a faster route out of the city.

The robotic voice played over the speakers in my car, directing me to take surface roads rather than get on the highway, which is typically the fastest way.

But Google somehow knew that there was a traffic jam ahead on the highway.

As I drove on the frontage road, I looked up at the interstate. It was at a standstill. Frustrated drivers honked and looked exasperated.

A couple of miles later, Google directed me to get back on the highway, right where the construction vehicles that were holding up traffic were blocking the road. Right after that, traffic thinned out, and I was driving the normal speed.

I couldn't help but feel a little bit of glee and satisfaction, that I had some sort of insider information others didn't have that allowed me to cut in line.

Google Maps is able to do this thanks to all of us. Hundreds of millions of people around the world give Google real-time data that it uses to analyze traffic and road conditions.

Here's how it works: All iPhones that have Google Maps open and Android phones that have location services turned on send anonymous bits of data back to Google. This allows the company to analyze the total number of cars, and how fast they're going, on a road at any given time.

Other popular GPS mapping apps, like Apple Maps, Waze, Nokia's HERE maps, and Mapquest, all offer traffic information, but the advantage Google has is the sheer number of people who use it, and the amount of data it has.

Google has built up a history over the last few years of what traffic is usually like on specific roads at specific times. That means it can predict how traffic will change over your drive - just because there's traffic around 60 miles ahead of you right now doesn't mean there will be traffic there when you arrive in an hour.

google maps android Google Maps on Android. Google

"It's not just what [traffic] is right now, but how do we expect it to change over the next hour or two hours," Amanda Leicht Moore, the lead product manager for Google Maps, said in an interview with Tech Insider.

Google Maps also incorporates traffic and incident data, like accident reports, from Waze, the popular navigation app that Google bought for more than $1 billion in 2013. Waze gets its information from users who report things like accidents on the road or traffic jams. Google also gets information from local departments of transportation.

Moore said that Google's database of historical traffic data allows the app to alert you if traffic is better or worse than it typically is, and how accidents and slowdowns will affect traffic on different roads in different parts of the world.google maps trafficLast weekend, Google told me that the fastest way home was through New Jersey, even though there was an accident and traffic causing delays.Screenshot / Tech Insider

"We can tell you if the traffic jam ahead - is that going to add five minutes to your trip? Or 10 minutes to your trip? Or 40 minutes to your trip?" she said. "T here's a lot of modeling and a lot of smarts that go into trying to anticipate how traffic will change."

Google Maps can even tell when there's a marathon happening in a city because a large group of people is moving faster than people usually move, but there are no cars on the roads.

Moore said that one of the priorities at Google Maps right now is to give people confidence that Google Maps is taking them the best way. To that end, Google Maps recently added explanations as to why it's routing you a certain way.

"When we tell you to take the side route it's so important for us to tell you [it's] because there is an incident over here, because you need to trust" the app, she said.

And if there's no way around a slowdown, or you're on the fastest route even if there is heavy traffic, Google will still tell you that you're going the best way.

I noticed this last weekend when Google told me that the fastest way home last weekend was through New Jersey instead of through Westchester County, even though there was an accident and traffic causing delays.

This is about "giving people confidence that they're going to get there faster," Moore said. "That we're taking them on the smartest, fastest route."