How machines ask a time server for the time, and why the answer is only good to a few milliseconds.
NTP (Network Time Protocol) is how almost every computer keeps its clock close to the right time. A machine asks a better clock "what time is it?", measures how long the answer took to travel, and corrects itself.
Every computer has a cheap quartz clock that drifts. NTP, one of the oldest internet protocols (designed by David Mills in the 1980s), fixes this by comparing your clock with a server whose clock is better. The servers are arranged in layers called strata. Stratum 0 is the real source (GPS receivers and atomic clocks). Stratum 1 servers are plugged directly into those. Stratum 2 servers sync from stratum 1, and so on.
One exchange works like this. The client records t1 (its clock when it sends the request). The server records t2 (its clock when the request arrives) and t3 (its clock when it sends the reply). The client records t4 (its clock when the reply arrives). Now:
The offset formula quietly assumes the request and the reply each took half of the delay. If the request took 5 ms and the reply took 25 ms, the formula is wrong by 10 ms (half the difference), and the client cannot tell.
| Step | What happens | Why |
|---|---|---|
| Poll several servers | Take samples from 3 to 5 sources | One server might be wrong |
| Filter samples | Keep the one with the shortest delay | A short trip leaves less room for asymmetry |
| Pick the agreeing group | Drop servers whose time disagrees with the majority | Removes broken or hijacked sources |
| Combine and correct | Use a weighted average, then fix the clock | Smoother and safer than trusting one answer |
| Adjust poll interval | Poll often at first, then every few minutes | Saves traffic once the clock is steady |
| Item | What it is | What to remember |
|---|---|---|
| ntpd | The classic NTP daemon | Mature, but slow to converge |
| chrony | A newer daemon (default on many Linux systems) | Faster to sync, copes well with sleeping VMs and bad networks |
| Leap second | One extra second added to UTC now and then | A clock may show 23:59:60 or repeat a second. Big sites 'smear' it over many hours instead |
| PTP | Precision Time Protocol, with hardware timestamps in network cards | Microsecond or better, but needs support from switches |
| NTS | Network Time Security | Adds authentication so nobody can fake the server |
| Monotonic clock | A clock that only goes forward and is not set by NTP | Use it to measure how long something took |
A simplified model: the server clock is perfect, the server needs 1 ms to reply, and the clock rate does not change during the exchange. Real NTP repeats this with several servers, throws away the worst samples (the longest delays), and filters the rest.
chronyc tracking shows the current offset, and chronyc sources shows which servers are used and how far off each one is.| Term | Meaning in easy words |
|---|---|
| NTP | Network Time Protocol, which sets a clock from a time server |
| Offset | How far the client clock is from the server clock |
| Delay | Round-trip network time, not counting the server's thinking time |
| t1, t2, t3, t4 | The four timestamps: client send, server receive, server send, client receive |
| Stratum | How many hops a server is from the real time source (0 is the best) |
| Slew | Gradually speeding up or slowing the clock to fix it, with no jump |
| Step | Setting the clock at once, which can make time jump backwards |
| Asymmetry | When the trip there and the trip back take different times |
| Jitter | How much the delay changes from one exchange to the next |
| Leap second | An extra second occasionally added to UTC |
| Leap smear | Spreading a leap second over many hours so no one sees a jump |
| PTP | Precision Time Protocol, a more accurate sync using hardware timestamps |
| Monotonic clock | A clock that only moves forward, ideal for measuring durations |
| Choice | We gain | We lose |
|---|---|---|
| Slew only | Time never jumps | A big error takes a long time to fix |
| Step when large | Fast recovery | Risk of time going backwards |
| Poll more often | Less drift between syncs | More traffic and more noise from one-off delays |
| Many sources | Resists a bad server | More setup and more to monitor |
| Local GPS or PTP | Microsecond accuracy | Hardware cost and special network gear |
| Leap smear | No odd 23:59:60 | Your clock differs from other clocks for a few hours |
end − start can be negative. Use a monotonic clock.