Two computers that disagree about the time cannot agree about order. They cannot decide which transaction came first, when a certificate expired, or how to merge two logs. Keeping clocks aligned sounds easy until you notice that the only way to tell a remote machine the time is to send it a message, and the message takes a while to arrive, and that delay is never the same twice. The Network Time Protocol, designed by David L. Mills at the University of Delaware and documented in RFC 958 in 1985, solves this well enough that it has kept the internet’s clocks in step ever since.

The idea

Spread authoritative time outward through a hierarchy of servers, and cancel the network’s unknown delay with four timestamps from a single exchange.

A hierarchy of strata

NTP arranges time sources into levels it calls strata. At the top, stratum 0, are the reference clocks themselves, such as atomic clocks and GPS receivers, which are not on the network. A stratum 1 server is directly attached to one of those references. A stratum 2 server sets its clock from stratum 1 servers, a stratum 3 from stratum 2, and so on down. Each level is a little less accurate than the one above, and the tree spreads authoritative time outward to millions of machines without every machine needing its own atomic clock.

NTP strata: reference clocks at stratum 0 feed a tree of servers, each level synchronizing from the one above.

The harder problem is the delay. A client cannot simply accept the timestamp a server sends, because that timestamp is already stale by the unknown travel time. NTP gets around this with four timestamps from a single exchange: when the client sent its request, when the server received it, when the server replied, and when the client got the reply. Call them t0, t1, t2, and t3. The protocol computes the clock offset as ((t1 minus t0) plus (t2 minus t3)) divided by 2, and the round-trip delay as (t3 minus t0) minus (t2 minus t1). The arithmetic assumes the path takes about the same time in each direction, and under that assumption the travel time cancels out, leaving an estimate of how far the two clocks actually differ. The client nudges its clock toward that offset, repeats, and converges.

Why it endures

NTP has been running since before 1985, which makes it one of the oldest internet protocols still in daily use. It was built on the DARPA-funded internet, and the same design carries time across data centers, financial systems, and phone networks today.

Sources