Network time: NTP and PTP
Every computer's clock drifts, and logs, certificates and trading all break when clocks disagree. Follow time from a GPS reference clock down the NTP strata to your laptop, work out the clock offset and round-trip delay from four real timestamps, then see how PTP uses hardware timestamps and boundary clocks to get below a microsecond.
6 quick questions
Pick an answer to see why. Your score saves with your progress.
01A client sends at t1 = 0 ms, the server receives at t2 = 95 ms and replies at t3 = 96 ms, and the reply arrives at t4 = 31 ms (each on its own clock). What is the round-trip delay?
Delay = (t4 − t1) − (t3 − t2) = 31 − 1 = 30 ms. The time the server spent working (t3 − t2) is taken out, and the two clocks never need to agree for this.
02With the same four timestamps, how far is the client's clock off?
((95 − 0) + (96 − 31)) / 2 = (95 + 65) / 2 = +80 ms. A positive offset means the server is ahead, so the client must move forward.
03Your laptop syncs from a stratum-2 server. What stratum is your laptop?
Each hop away from the reference clock adds one. Stratum 1 is wired to the reference clock, stratum 2 syncs from it, and your laptop is one more hop. Stratum 16 means not synchronised.
04What does NTP assume that limits its accuracy?
If the trip out takes longer than the trip back, half the difference shows up as clock error. The error can never be more than half the round-trip delay (±15 ms here).
05How does PTP get much closer than NTP?
Software timestamps include unpredictable delays inside the operating system and switch queues. PTP stamps packets in hardware and lets switches act as boundary clocks, so each short link is measured separately.
06A laptop's clock is wrongly set two years in the past. What happens when it opens an HTTPS site?
Every certificate has a notBefore and a notAfter date (RFC 5280). The browser checks them against its own clock, so a wrong clock makes a good certificate look not yet valid or expired, and the TLS connection fails.
Glossary
- NTP
- Network Time Protocol (RFC 5905): a client and server swap four timestamps over UDP port 123 to set the client's clock.
- Clock offset
- How far one clock is ahead of or behind another; NTP's θ = ((t2 − t1) + (t3 − t4)) / 2.
- Round-trip delay
- Time on the network for the request and reply together, without the server's own work: (t4 − t1) − (t3 − t2).
- Stratum
- How many hops a clock is from a reference clock: stratum 1 is wired to it, stratum 2 syncs from stratum 1, and so on; 16 means unsynchronised.
- Reference clock
- A source of true time such as a GPS receiver or an atomic clock, called stratum 0.
- Slew
- Correcting a clock gradually by running it slightly fast or slow, so time never jumps or runs backwards.
- PTP
- Precision Time Protocol (IEEE 1588): like NTP's four timestamps, but stamped in hardware for sub-microsecond accuracy.
- Grandmaster
- The best clock on a PTP network, chosen automatically; every other PTP clock syncs to it, directly or through boundary clocks.
- Boundary clock
- A PTP switch that syncs to the grandmaster on one port and acts as master for the devices on its other ports.
Notes and sources
- NTP version 4 is RFC 5905: a 48-byte header over UDP port 123, offset θ = ((t2 − t1) + (t3 − t4)) / 2 and delay δ = (t4 − t1) − (t3 − t2). Real clients poll several servers repeatedly and filter the samples.
- Clock readings are illustrative (the laptop 80 ms slow, 15 ms each way); the arithmetic on them is exact. The 128 ms step threshold and 500 ppm slew limit are the reference implementation's defaults.
- PTP is IEEE 1588-2019. The example uses relative nanoseconds since the Sync left; real PTP timestamps count seconds and nanoseconds since 1970 on the TAI scale.
- 198.51.100.1 and 203.0.113.123 are RFC 5737 documentation addresses; 192.168.1.0/24 is a private home range (RFC 1918). GPS time is 18 s ahead of UTC.
Quiz Unlocks after the last step.