How Network Time Protocol (NTP) works
-
Device A sends an NTP message to device B. The message carries a timestamp when it leaves device A. The timestamp is 10:00:00 am (T1).
- When this NTP message arrives at device B, device B adds its own timestamp. The timestamp is 11:00:01 am (T2).
- When this NTP message leaves device B, device B adds its own timestamp and changes the timestamp to 11:00:02 (T3).
- When device A receives the response message, the local time of device A is 10:00:03 am (T4).
-
At this point, device A has enough information to calculate two important parameters:
-
The round-trip delay of NTP packets is Delay = (T4-T1)-(T3-T2) = 2 seconds.
-
The time difference between device A and device B is offset = ((T2-T1) + (T3-T4))/ 2 = 1 hour.
-
- In a client-server basis;
- In a peer to peer mode;
- Sending the time using broadcast/multicast.
Users can choose the appropriate working mode according to their needs. When the IP address of the server or peer cannot be determined, and there are many devices that need to be synchronized on the network, the clock synchronization can be achieved through broadcast or multicast mode; in the server and peer mode, the device starts from the specified server or peer.