How PTP Uses UDP to Synchronize Network Clocks
The Precision Time Protocol (PTP), defined under IEEE 1588, provides sub-microsecond clock synchronization across distributed network devices. To achieve this high level of accuracy, PTP frequently operates over the User Datagram Protocol (UDP) on IPv4 or IPv6 networks. By leveraging UDP’s low overhead, multicast capabilities, and specific port assignments for hardware timestamping, PTP can accurately measure and compensate for network delay and clock offset between a primary clock (Master) and secondary clocks (Slaves).
Dedicated UDP Ports and Message Types
PTP separates its network traffic into two primary categories using dedicated UDP port numbers to ensure timing accuracy:
- UDP Port 319 (Event Messages): Used for
time-critical messages that require precise hardware or software
timestamping upon transmission and reception. Key event messages include
Sync,Delay_Req,Pdelay_Req, andPdelay_Resp. - UDP Port 320 (General Messages): Used for
non-time-critical management and informational data that do not require
exact timestamps. These include
Follow_Up,Delay_Resp,Pdelay_Resp_Follow_Up,Announce, andManagementmessages.
Separating these packets allows network interface cards (NICs) and switches to quickly identify Port 319 traffic and capture hardware-level timestamps at the physical layer (PHY) without packet-processing delays.
The Four-Timestamp Synchronization Process
Synchronization relies on a two-way exchange of UDP datagrams to calculate the network delay and the clock difference between the Master and Slave.
- Master to Slave (Sync): The Master sends a UDP
Syncpacket on port 319 and records its egress timestamp (\(t_1\)). The Slave receives this packet and records its ingress timestamp (\(t_2\)). If hardware limitations prevent inserting \(t_1\) directly into theSyncpacket, the Master sends a standard UDPFollow_Uppacket on port 320 containing the value of \(t_1\). - Slave to Master (Delay Request): The Slave sends a
UDP
Delay_Reqpacket to the Master on port 319, recording its egress timestamp (\(t_3\)). - Master Response (Delay Response): The Master
receives the
Delay_Req, records its ingress timestamp (\(t_4\)), and sends a UDPDelay_Resppacket on port 320 back to the Slave containing the value of \(t_4\).
Offset and Delay Calculation
Once the Slave collects all four timestamps (\(t_1, t_2, t_3, t_4\)) via the UDP exchanges, it calculates the mean propagation delay and clock offset assuming symmetric network transit times:
- Mean Path Delay: \(\text{Delay} = \frac{(t_2 - t_1) + (t_4 - t_3)}{2}\)
- Clock Offset: \(\text{Offset} = (t_2 - t_1) - \text{Delay}\)
The Slave then adjusts its local clock by the calculated offset to align precisely with the Master clock.
Why PTP Uses UDP
- Connectionless Transport: Unlike TCP, UDP does not require handshakes, retransmissions, or flow-control mechanisms that introduce variable queuing delays (jitter).
- Multicast Distribution: PTP utilizes standard
multicast IP addresses (such as
224.0.1.129for IPv4) over UDP, enabling one Master to synchronize thousands of Slave nodes simultaneously without distinct individual connections. - Deterministic Latency: The minimal header size of UDP ensures fast packet generation, serialization, and parsing across networking hardware.