When your phone shows the right time to the second, you can thank a protocol that most people have never heard of. The Network Time Protocol, NTP, quietly corrects the clocks on billions of devices every day. It is one of the oldest protocols still in use on the internet, and it solves a hard problem: how do you tell the time over a network that delays messages by an unpredictable amount?
Every computer has a clock built from a small quartz crystal, just like a cheap watch. Left alone it can drift by a second or two per day, and more when it is hot or busy. For one person that is a nuisance. For a bank timestamping trades, a network matching call records or a system verifying security certificates, a clock that is out by even a second can cause real errors.
The fix is to compare your clock with a better one. That is easy for a wristwatch, but over the internet the answer to "what time is it?" is old by the time it arrives. NTP's job is to estimate and remove that delay.
NTP organises time sources in layers called strata. At the top, stratum 0 is the reference itself: an atomic clock, or a GPS receiver that provides atomic-quality time. These devices are not on the network directly. A stratum 1 server is connected to one of them and shares the time with the network. A stratum 2 server synchronises with stratum 1 servers, stratum 3 with stratum 2, and so on up to stratum 15. Stratum 16 means "not synchronised".
Each step adds a little error, but with careful design the loss is small. Your computer is usually at stratum 2 or 3, taking its time from a group of servers rather than a single one. The chain traces back to the same references we describe in our guide to how atomic clocks work and how GPS time relates to UTC.
The key idea in NTP is a simple exchange of four timestamps. Your device sends a request and records the time on its own clock, t1. The server records when the request arrives, t2, and when it sends the reply, t3. Your device records when the reply arrives, t4.
From these, two numbers can be worked out. The round-trip delay is the total time minus the time the server spent processing: (t4 − t1) − (t3 − t2). The clock offset, the amount your clock is wrong by, is estimated as ((t2 − t1) + (t3 − t4)) ÷ 2.
The offset estimate assumes that the outbound and return trips take equal time. That is usually close to true, and when it is not, it is the main source of error. NTP reduces that error by talking to several servers, discarding unreliable ones and combining the rest.
Over the public internet, NTP typically keeps a clock within a few milliseconds to a few tens of milliseconds of the true time, depending on the quality of the connection. On a local network with a nearby server it can do better than one millisecond. That is far more than enough for everyday use. To be sure whether you need more, compare it with what you are doing. A person reacts in about 200 milliseconds, so an error of 10 milliseconds is invisible.
Applications that need more precision, such as financial trading, telecoms and scientific instruments, use the Precision Time Protocol (PTP), which can reach sub-microsecond accuracy with the help of special network hardware.
Many operating systems point to default servers run by their makers, such as Apple, Microsoft or Google. There is also the NTP Pool, a large volunteer-run cluster of servers that distributes requests across thousands of machines worldwide, and national laboratories such as NIST in the United States and PTB in Germany operate public servers.
NTP runs over UDP on port 123. Its modern security extension, Network Time Security, protects against someone tampering with the time on the way to you.
NTP can announce a leap second in advance, but handling it is difficult, because a minute with 61 seconds breaks software that assumes every minute has 60. Some large providers avoid the problem by "smearing" the extra second, spreading it in tiny steps over many hours. Others step the clock. This is one reason the world has agreed to stop adding leap seconds by 2035.
On most systems, time synchronisation is automatic, and you can confirm it:
If your clock is still wrong, the usual causes are a dead battery on an old computer, a blocked network connection or an incorrect time zone, rather than a failure of NTP itself.
A clock shown on a web page generally takes its time from your own device. That means it can only be as accurate as your device's synchronisation, plus a small delay from the network. If your device is synchronised with NTP, the web page will be right to well within a second, which is more than enough for setting a watch, as we explain in our guide to how to calibrate a watch.