Our computers don't really know what time it is

·2 min read ·#systems#time#ntp#linux

Inside every machine is a tiny quartz crystal vibrating 32,768 times per second. Your computer counts those vibrations and treats that as time, until something more accurate corrects it.

I pointed chrony at my own system out of curiosity. It reported my clock running 4.9 ppm slow, which works out to roughly half a second lost every day if nothing corrected it. That sent me down the rabbit hole of how the entire planet agrees on time.

The reference clock isn’t on Earth#

Since 1967, a second has officially meant exactly 9,192,631,770 oscillations of a cesium atom. Time stopped being tied to the Earth’s rotation and became tied to physics instead.

Atomic clocks are the most accurate timekeepers we’ve ever built, so naturally we put them in space. Every GPS satellite carries atomic clocks onboard. Your phone listens to several satellites at once and works out location from how long each signal took to arrive.

Clocks in orbit tick about 38 microseconds faster per day than clocks on Earth, because gravity is weaker farther from the planet. Without constant correction, GPS positions would drift by roughly 10 km a day.

The part that surprised me#

Your phone doesn’t have an atomic clock inside it. GPS is also solving for your phone’s clock error. That’s why GPS needs four satellites instead of three: three would be enough if your phone already knew the exact time, but it doesn’t, so the fourth satellite exists largely to fix the phone’s clock.

As a side effect of figuring out where it is, every smartphone on Earth is constantly receiving atomic-clock-grade time for free.

Bringing it down to ordinary systems#

The protocol that carries this time into normal machines is NTP. Mine settled at stratum 3, three hops from an atomic clock somewhere on Earth.

When milliseconds aren’t enough, there’s PTP, the Precision Time Protocol. Instead of relying on software timing, the network card timestamps packets directly in hardware, so OS scheduling delays don’t distort the measurement. That level of timing quietly powers finance, telecom, aviation, and a lot of the internet.

And the moment clocks drift too far, ordinary things start failing:

  • TLS certificates stop validating
  • software updates fail
  • distributed systems start disagreeing about reality

All of this machinery runs quietly underneath almost everything we do online. Until recently, I’d never really thought about it.


This started as a post on LinkedIn.