How NTP works
Figure 32 shows how NTP synchronizes the system time between two devices (Device A and Device B, in this example). Assume that:
Prior to the time synchronization, the time is set to 10:00:00 am for Device A and 11:00:00 am for Device B.
Device B is used as the NTP server. Device A is to be synchronized to Device B.
It takes 1 second for an NTP message to travel from Device A to Device B, and from Device B to Device A.
It takes 1 second for Device B to process the NTP message.
Figure 32: Basic work flow
The synchronization process is as follows:
Device A sends Device B an NTP message, which is timestamped when it leaves Device A. The time stamp is 10:00:00 am (T1).
When this NTP message arrives at Device B, Device B adds a timestamp showing the time when the message arrived at Device B. The timestamp is 11:00:01 am (T2).
When the NTP message leaves Device B, Device B adds a timestamp showing the time when the message left Device B. The timestamp is 11:00:02 am (T3).
When Device A receives the NTP message, the local time of Device A is 10:00:03 am (T4).
Up to now, Device A can calculate the following parameters based on the timestamps:
The roundtrip delay of the NTP message: Delay = (T4 – T1) – (T3 – T2) = 2 seconds.
Time difference between Device A and Device B: Offset = [ (T2 – T1) + (T3 – T4) ] /2 = 1 hour.
Based on these parameters, Device A can be synchronized to Device B.
This is only a rough description of the work mechanism of NTP. For more information, see the related protocols and standards.