How NTP Achieves High Precision Using UDP

The Network Time Protocol (NTP) achieves sub-millisecond precision over variable-latency networks by combining the minimal latency of the User Datagram Protocol (UDP) with a four-timestamp exchange algorithm and advanced statistical filtering. By operating over UDP, NTP avoids the transmission delays, connection handshakes, and retransmission overhead inherent in connection-oriented protocols like TCP. This foundational transport efficiency allows NTP clients and servers to accurately calculate round-trip network delays, estimate local clock offsets, and dynamically adjust system clocks without introducing latency artifacts.

The Advantage of UDP Over TCP

NTP operates over UDP port 123. TCP requires a three-way handshake, maintains connection states, and automatically retransmits lost packets. These mechanisms introduce unpredictable queuing delays, jitter, and head-of-line blocking, which corrupt precise timing measurements.

UDP is connectionless and lightweight. It transmits packets immediately without session negotiation or acknowledgment waits. If an NTP packet is lost or delayed, the protocol simply drops that sample and relies on subsequent polls rather than waiting for retransmissions. This ensures every processed time sample represents the most direct, real-time path through the network.

The Four-Timestamp Handshake

To neutralize the variable network transit times inherent to packet-switched networks, NTP uses an exchange of four distinct timestamps:

  1. \(T_1\) (Origin Timestamp): The client records the local time when the NTP request packet is sent.
  2. \(T_2\) (Receive Timestamp): The server records its local time upon receiving the request.
  3. \(T_3\) (Transmit Timestamp): The server records its local time when sending the reply packet.
  4. \(T_4\) (Destination Timestamp): The client records the local time upon receiving the reply.
Client                     Server
  |                          |
  |--- T1 (Client Send) ---->|
  |                          |--- T2 (Server Receive)
  |                          |--- T3 (Server Transmit)
  |<-- T4 (Client Receive)---|
  |                          |

Calculating Round-Trip Delay and Clock Offset

Using these four values, the client calculates two critical metrics under the baseline assumption that network path latency is symmetrical:

By subtracting the server’s internal turnaround time (\(T_3 - T_2\)) from the total elapsed time (\(T_4 - T_1\)), NTP isolates pure network transit delay, allowing precise offset corrections down to milliseconds over the public internet.

Statistical Filtering and Clock Discipline

A single measurement can still be skewed by asymmetric routing or temporary network congestion. NTP mitigates this by maintaining a sliding window of recent timestamp exchanges and applying statistical algorithms:

Hardware Timestamping Integration

In modern high-precision deployments, NTP bypasses operating system kernel delays through hardware timestamping. Network Interface Cards (NICs) capture the \(T_1\) through \(T_4\) timestamps at the physical layer (PHY) as the UDP packet enters or exits the network port. This eliminates interrupt latency and OS scheduling jitter, allowing NTP over UDP to achieve microsecond-level accuracy.