How Clock Synchronization Works

Two machines can estimate their clock difference by exchanging timestamped messages. Step through the process below, or let it play automatically.

Ready
Press "Next Step" or "Auto Play" to begin The two machines start with different clocks. We'll walk through a four-timestamp exchange to synchronize them.

Calculation

Collected timestamps
t1 = ?   t2 = ?   t3 = ?   t4 = ?
The problem — why can't we just compare clocks?
(t2 − t1) = ?  ← this is NOT the pure offset; it's offset + forward delay
(t3 − t4) = ?  ← also not pure offset; it's offset − return delay
Each measurement mixes the offset we want with an unknown one-way delay we can't measure!
The trick — add both directions so the unknown delays cancel
What each measurement really contains:
  (t2 − t1) = offset + delay→
  (t3 − t4) = offset delay←

Add them together:
  (t2 − t1) + (t3 − t4) = (offset + delay→) + (offset delay←)
                                 = 2·offset + delay→delay←   ← delays cancel when equal!
                                 = 2·offset   (when delay→ = delay←)

The offsets ADD UP (both +offset), while the delays have opposite signs (+delay→, −delay←) and cancel! Divide by 2:
  offset = ((t2 − t1) + (t3 − t4)) / 2
  = (? + ?) / 2 = ?

This is exact when delay→ = delay←. Any asymmetry causes error = (delay→ − delay←) / 2.
How confident are we? — round-trip delay as a quality measure
RTT = (t4 − t1) − (t3 − t2)
= (?) − (?) = ?
RTT is not used in the offset formula — it tells us the maximum possible error (RTT/2).
A smaller RTT means a tighter bound on accuracy. NTP picks the sample with the lowest RTT.
Accuracy check
True offset: ?  |  Estimated: ?  |  Error: ?
Key insight: We can't observe the offset directly because every comparison includes unknown network delay. By averaging both directions, the delays cancel (assuming symmetry). The round-trip delay isn't part of the offset formula — it measures how trustworthy the estimate is. Try making delays asymmetric (Delay → ≠ Delay ←) to see when the estimate breaks down.
200
120
120
Local clock
Reference clock
Message packet
Calculated result