Network Time Protocol (NTP), much like Precision Time Protocol (PTP), is a method of delivering accurate time to devices on a network. NTP does this using a ping-pong time difference calculation mechanism, where the client will send out a message and the server will respond (like master and slave in the case of PTP).
- The client sends out an NTP message to the server, which is timestamped with T1 as it is sent
- The server receives the message, and timestamps its arrival with T2
- The server changes the IP addresses in the NTP message, adds in T2, and other field data
- The server sends the NTP message back, which is timestamped with T3 as it is sent
- The client timestamps the arrival of the NTP message with T4. Using T1-T4, the client calculates offset and delay and adjusts its time accordingly
Once the client has all four timestamps, it calculates the offset between the two clocks, and the round trip delay as follows.
The offset calculation assumes that the network delay is the same in both directions, hence the round trip delay is monitored to check for this.
The calculated offset and delay values are filtered for outliers, and subjected to statistical analysis. The client's time is then adjusted by subtracting of a small fraction of the filtered offset value off its current time. This process is repeated over many client to server message exchanges to eventually reduce the offset between the client and server to as close to zero as possible.