NTP: How the Internet Keeps Its Clocks in Agreement
See how the Network Time Protocol measures delay, why accurate clocks matter and how to check and fix time on your computer.
Key takeaways
- NTP estimates both the network delay and the clock error by using four timestamps from one exchange.
- Time sources form levels called strata, starting with precise reference clocks and passing time downward.
- Accurate time is needed for certificates, one-time passwords, logs and many distributed systems.
- Most devices only need automatic time turned on; servers and networks benefit from several sources and monitoring.
The Network Time Protocol, or NTP, keeps computer clocks accurate by asking time servers what time it is and correcting for the delay of the question and answer. Your computer, phone and router almost certainly use it, or a simpler relative, without any action from you.
It matters more than it sounds. A clock that is badly wrong can make secure websites show certificate errors, reject login codes and scramble the order of events in logs.
Why clocks drift and why it matters
A typical computer keeps time by counting oscillations of a small crystal. Crystals are good but imperfect, and their rate changes with temperature and age. Left alone, a clock gains or loses time, perhaps a noticeable amount over weeks. Virtual machines can drift or jump when they're paused or moved.
Many systems assume clocks roughly agree.
- Certificates have a start and end date, so a wrong clock can make a valid one look expired or not yet valid, as listed among browser certificate errors.
- One-time codes from authenticator apps are calculated from the current time.
- Network logins such as Kerberos reject requests whose time differs too much.
- Logs from several machines can only be lined up if their clocks agree.
- Signed records such as those in DNSSEC are valid only within time windows.
Strata: where time comes from
NTP organizes sources into levels called strata.
A lower number means fewer network hops from a reference clock, not automatically a better answer. A nearby, stable stratum 2 server may serve you better than a distant, congested stratum 1. A stratum value of 16 conventionally means unsynchronized.
NTP delivers UTC, Coordinated Universal Time. Time zones and daylight saving rules are applied by your operating system afterward. If your clock is exactly one hour off, suspect the time zone settings and not NTP. Unix timestamps and time zones explains the distinction.
The four timestamps
A message takes time to travel, so a server's answer is already stale when it arrives. NTP's solution is elegant. In one exchange it records:
- T1: when the client sends the request, by the client's clock.
- T2: when the server receives it, by the server's clock.
- T3: when the server sends the reply, by the server's clock.
- T4: when the client receives it, by the client's clock.
The round-trip delay is the total time the client waited, minus the time the server spent: (T4 - T1) - (T3 - T2).
The clock offset, how far the client is from the server, is estimated as ((T2 - T1) + (T3 - T4)) / 2.
A worked example
Say the client's clock is 500 milliseconds behind, each direction takes 40 ms and the server takes 1 ms to respond. Measured in milliseconds from an arbitrary point on the client's clock, T1 is 1000. The server receives the request 40 ms later, which on its faster clock reads 1540. It replies at 1541. The reply reaches the client 40 ms after that, when the client's clock reads 1081.
Delay is (1081 - 1000) - (1541 - 1540), which is 80 ms. Offset is ((1540 - 1000) + (1541 - 1081)) / 2, which is (540 + 460) / 2, or 500 ms. The client learns it is half a second slow.
The weak point is the assumption that both directions take equally long. If the path is asymmetric, say a congested upload, the estimate is off by half the difference. That's why NTP samples repeatedly and favors measurements with low delay.
Choosing sources and correcting gently
A good NTP client doesn't trust one server. It polls several, discards those that disagree with the majority and combines the rest. With only two sources that disagree, it can't tell which is wrong, so administrators commonly configure at least four.
It also learns how fast the local clock drifts and compensates. Small errors are corrected by slewing: running the clock slightly faster or slower so time never jumps backward. Large errors may be fixed by stepping, setting the clock at once, typically at startup.
NTP version 4 is specified in RFC 5905 and uses UDP port 123. It grew from work led by David Mills beginning in the 1980s. SNTP is a simplified profile that uses the same message format with less filtering, adequate for many simple devices. Where much finer precision is needed, such as some industrial, telecom and measurement networks, the Precision Time Protocol (IEEE 1588) uses hardware timestamping on suitable equipment.
Checking time on your computer
For most people the fix is a toggle: turn on automatic date and time in the system settings and check the time zone. Menu names vary by version.
On Windows, in a command prompt or PowerShell:
w32tm /query /status
w32tm /resync The second command usually needs an elevated window, and the time service has to be running.
On many Linux systems:
timedatectl If the system uses chrony, chronyc tracking shows the offset and chronyc sources -v lists the servers.
On macOS you can compare against a server without changing anything:
sntp time.apple.com You can also convert between formats with the timestamp converter when comparing log entries.
How often NTP asks
NTP is light on the network. A client doesn't ask continuously. It typically starts with fairly frequent queries after booting, to get a good estimate quickly, then stretches the interval as the clock proves stable, often to many minutes. If measurements start to scatter or the clock wanders, it polls more often again. Each exchange is a single small packet in each direction.
The software also keeps statistics for every source: the measured offset, the round-trip delay and the variation between samples, often called jitter. A source with a small delay and steady results earns more trust. One that is consistently far from the others is set aside, however confident it claims to be.
This is why a freshly configured system may not look synchronized in the first seconds. It is collecting samples before it commits. When you check status, look for which server has been selected, how large the offset is and when the last successful update happened. An old "last update" time usually points to a network or firewall problem.
Time in logs and investigations
When something goes wrong across several machines, accurate time is what lets you rebuild the story. Say a user reports a failed payment at a particular moment. You may need to line up the web server's log, the database's log and a firewall record. If one of them is two minutes off, cause can appear to come after effect.
Two habits help. Record timestamps in UTC, or include the offset from UTC in every entry, so that daylight saving changes don't create repeated or missing hours. And monitor clock offset like any other health measure, so you learn about a drifting machine before you need its logs.
Running time for a network
For an office or lab, a tidy arrangement is to have one or two local machines, or the router, synchronize with outside sources, and point everything else at them. In a Windows domain, members normally follow the domain's time hierarchy, so change the settings at its top and not on individual PCs.
Public pools such as pool.ntp.org distribute requests among many volunteer servers. Operating system and device makers also run their own. Follow the usage policy of whatever you choose, and don't poll more often than your software's defaults.
Check these if synchronization fails:
- A firewall blocking UDP port 123.
- A wrong or unresolvable server name.
- A virtual machine fighting between host-provided time and NTP.
- A dead battery on an older machine's hardware clock, which makes it boot far in the past.
- A very large initial error that the client refuses to correct without being told to.
Security of time
Classic NTP replies aren't strongly authenticated, so someone positioned on the network could try to feed false time. Using several independent sources helps. Network Time Security (RFC 8915) adds cryptographic protection, using a TLS-based key exchange, and is available in some client software and public services.
Badly configured NTP servers have also been abused to magnify denial-of-service traffic through old diagnostic queries. If you run a server, keep it updated, disable remote monitoring queries you don't need and limit who can use it.
Leap seconds and rollovers
Earth's rotation isn't perfectly steady, so UTC has occasionally gained a leap second to stay close to astronomical time. These have caused software bugs, and some large operators "smear" the extra second across many hours. International metrology bodies decided in 2022 to move away from the practice by 2035, and in October 2026 brought the date forward: from May 20, 2027, UTC may drift up to an hour from astronomical time, so no routine leap seconds are expected for centuries. Software still has to handle past ones, so check current guidance if your system depends on the details. Don't mix smearing and non-smearing servers in one configuration.
NTP's timestamp counts seconds from 1900 in a 32-bit field, which wraps around in 2036. The protocol design anticipates numbered eras, and maintained implementations handle it, but very old embedded devices deserve a look before then.
Common questions
How accurate is NTP?
It depends on the path. Over a good local network, errors can be well under a millisecond, and across the public internet they're commonly in the milliseconds, worse over unstable or asymmetric links.
Do phones use NTP?
Phones may get time from the mobile network, satellite positioning or internet time servers, depending on the device and settings. For everyday purposes, leaving automatic time on is the right choice.