Open in app
Cover art for How your phone keeps perfect time with a drifting crystal

How your phone keeps perfect time with a drifting crystal

Technology · 5 min listen

Get the app on mobile
Download on the App Store Get it on Google Play
Cover art for How your phone keeps perfect time with a drifting crystal
0:00
0:00
Transcript

HostWe all tend to trust our phones more than almost anything else in our lives. If the phone says it's seven thirty in the morning, we get out of bed, and we never really stop to wonder if that number is actually right. But it turns out the clock inside your phone isn't quite as solid as it looks.

GuestIt's funny because the heart of your phone is actually a tiny, very cheap piece of rock. If you could look inside the casing, you would see a sliver of quartz crystal shaped like a small tuning fork. This little fork is made to vibrate at a very specific rate of thirty two thousand seven hundred and sixty eight times every second. Engineers chose that specific number because it's a perfect power of two. If you keep cutting that number in half, fifteen times in a row, you get exactly one. That makes it incredibly easy for the simple digital chips in your phone to count those vibrations and know when one full second has passed.

HostSo if we have this perfect little tuning fork made of crystal, why do we even need to worry about it being wrong?

GuestWell, the problem is that these crystals are mass produced and they're very sensitive to the world around them. Quartz is a physical thing, so it changes based on its environment. The biggest issue is temperature. If your phone is sitting on a cold nightstand, that crystal fork vibrates at one speed. But the moment you pick it up and put it in your warm pocket, the heat from your body actually changes how the crystal moves. It might speed up or slow down just because it got a few degrees warmer. Without any help, that tiny drift would add up fast. Your phone could easily gain or lose several seconds every single day. That doesn't sound like much, but in a week, your morning alarm would be off by a minute. In a month, your whole calendar would be a mess.

HostI had no idea it was that flaky. It feels like my phone is always dead on, though. How does it fix itself if the hardware is that moody?

GuestIt does it by admitting it can't trust itself. Your phone is part of a giant global ladder called the Network Time Protocol. At the very top of this ladder, which experts call Stratum Zero, are the masters of time. These are massive atomic clocks on the ground and GPS satellites up in space. They use the vibrations of atoms to keep time so well they only lose a second every few billion years. Your phone knows it's at the bottom of the ladder, so it acts like a student constantly checking its notes against a teacher. It's always talking to cell towers and internet servers to see what the real time is. Instead of letting that cheap crystal run the show, the phone uses those high tech signals to discipline the quartz and keep it in line.

HostBut even that seems like it would've a catch. If my phone is asking a server hundreds of miles away for the time, doesn't it take time for that message to travel? By the time the answer gets to my phone, it must be old news.

GuestThat's a huge hurdle because the speed of light is fast, but it's not instant. Plus, the internet can be crowded and slow. To fix this, your phone does some clever math to deal with what people call network jitter or lag. When your phone asks for the time, it carefully notes exactly when it sent the request and exactly when the answer came back. By measuring that round trip time, the phone can figure out how long the message was stuck in the wires. It takes that travel delay, cuts it in half, and subtracts it from the time it just got. It basically says, okay, this signal tells me it's noon, but it took ten milliseconds to get here, so I know it's actually noon and ten milliseconds right now.

HostThat's a lot of work just to keep the clock from drifting. But what happens when the phone realizes it's actually off? Does it just snap the clock forward? I feel like I would notice if the time just jumped.

GuestYou would, and more importantly, your apps would notice too. If the clock suddenly jumped forward or backward by three seconds, it would cause chaos. A music app might glitch out because the song file doesn't match the time, or a security app might think a login is fake because the seconds don't line up. To avoid this, phones use a trick called clock slewing. Instead of a sudden jump, the phone slightly speeds up or slows down how fast the clock ticks in its software. It's like a runner realizing they're a bit behind and picking up their pace just enough to catch up over the next few minutes. It makes the correction so smooth and tiny that you never see the clock skip, and your apps never know anything was wrong.

HostIt's wild that this perfect clock we carry around is really just a cheap crystal and a lot of very fast math.

GuestIt really comes down to the fact that your phone is never actually sure what time it's on its own; it just spends all day asking the smartest clocks in the world for the right answer.

HostThe next time I feel my phone warming up in my hand, I'll think about that little crystal fork starting to drift and the hidden race it has to run just to stay on track.

Made with Wander

A world of curiosity you can listen to. Explore endless questions, or ask your own.

Get the app