Network Time Protocol Version 4: Protocol and Algorithms Specification
obsoletes
- rfc-1305 — Network Time Protocol (Version 3) Specification, Implementation and Analysis
- rfc-4330 — Simple Network Time Protocol (SNTP) Version 4 for IPv4, IPv6 and OSI
updated by
Extracted elements (32)
NTP uses UDP rather than TCP because retransmissions in a reliable transport protocol would increase measured delay values and introduce errors; the returnable-time on-wire protocol depends only on measured clock offsets and is inherently tolerant of lost or reordered packets without needing retransmission.
NTPv4 encourages use of floating double arithmetic throughout the implementation. First-order timestamp differences (which are small relative to the seconds magnitude) are converted to floating double for further processing, restoring the unambiguous offset/delay computation range from 34 years (64-bit integer) to 68 years without loss of precision.
The synchronization subnet topology uses a variant of the Bellman-Ford distributed routing algorithm to compute the shortest-path spanning tree rooted at primary servers, automatically reorganizing to provide the most accurate and reliable time even when failures occur, without requiring an explicit election protocol.
NTPv4 is backwards compatible with NTPv3 (RFC 1305) and SNTPv4 (RFC 4330), which it obsoletes; SNTPv4 is a strict subset of NTPv4. Minor changes to header fields do not affect interoperability between NTPv4 and previous versions.
When an NTPv4 server uses IPv6 and serves an NTPv3 client, the Reference ID field (containing the first four octets of the MD5 hash of the IPv6 address) appears as a random value to the NTPv3 client, which may prevent detection of timing loops.
All fully NTPv4-compliant servers and clients MUST implement the entire suite of algorithms described in the specification. Secondary servers SHOULD be fully NTPv4-compliant to maintain stability in large NTP subnets. Alternative algorithms MAY be used only if their output is identical to those specified.
If authentication is implemented, the MD5-keyed hash algorithm described in RFC 1321 must be supported. The MAC is computed over the key concatenated with all NTP header and extension fields (but not the Key Identifier or Message Digest fields themselves).
KoD Receive and Transmit Timestamps MUST NOT be relied upon to contain valid values and MUST be discarded. Kiss codes beginning with 'X' are reserved for unregistered experimentation and MUST be ignored if not recognized.
To minimize bias and make timestamps unpredictable to an intruder, the non-significant bits of timestamp fractions should be set to an unbiased random bit string. Clock resolution is defined as 2^(-p) seconds where p is the number of significant bits.
Upon receiving a KoD packet with kiss code DENY or RSTR, the client MUST demobilize all associations to that server and stop sending packets to it. Upon receiving kiss code RATE, the client MUST immediately reduce its polling interval to that server and continue reducing it each time a RATE code is received.
When a negative round-trip delay results from a large initial frequency offset combined with a short polling interval, the value of delta MUST be clamped to not less than s.rho (the system precision in seconds) to prevent misleading subsequent computations.
Before updating state variables on packet receipt, two sanity checks detect duplicate/replay packets (transmit timestamp t3 matches state variable T3) and bogus packets (origin timestamp t1 does not match state variable T1). To resist replay of the last transmitted packet, the xmt state variable is set to zero immediately after a successful bogus check.
Kiss-o'-Death (KoD) packets carry Stratum = 0 and a four-character left-justified zero-filled ASCII kiss code in the Reference ID field. Defined kiss codes include DENY (access denied), RSTR (local policy denial), RATE (rate exceeded), AUTH (authentication failed), CRYP (cryptographic failure), INIT (not yet synchronized), and STEP (step change occurred). The Receive and Transmit Timestamps in KoD packets are undefined.
NTP defines six association modes: Symmetric Active (1), Symmetric Passive (2), Client (3), Server (4), Broadcast Server (5), and Broadcast Client (6). A client (mode 3) sends mode-3 packets and receives mode-4 responses; symmetric active peers exchange mode-1 packets. Persistent associations are mobilized at startup; ephemeral associations are mobilized on packet arrival and demobilized on error or timeout.
The clock discipline algorithm is a hybrid PLL/FLL that controls both time and frequency of the system clock (modeled as a VFO). The poll exponent tau ranges from MINPOLL (4, 16 s) to MAXPOLL (17, 36 h); the loop time constant T_c = 2^tau is dynamically adjusted. The adjtime() function is used for small adjustments; settimeofday() for adjustments exceeding the step threshold.
The clock filter algorithm maintains a shift register of the eight most recent (offset, delay, dispersion, time) samples per server and selects the sample with the smallest delay as the best estimate. It outputs the statistics theta, delta, epsilon, and psi that are passed to the system process.
The Leap Indicator (LI) is a 2-bit field: 0 = no warning, 1 = last minute of day has 61 seconds, 2 = last minute has 59 seconds, 3 = clock unsynchronized. A value of 3 propagates through the subnet to indicate that the time source is not trusted.
The manycast dynamic server discovery mechanism sends client (mode 3) packets to an IPv4 broadcast/multicast or IPv6 multicast group address with TTL starting at 1 and incrementing until the minimum number of associations is reached or TTL reaches 255 (maximum). Suitable servers respond via unicast mode-4 packets; the client mobilizes ephemeral associations that compete via the mitigation algorithms.
The on-wire protocol exchanges four timestamps: t1 (client departure), t2 (server arrival), t3 (server departure), t4 (client arrival). Clock offset theta = [(T2-T1)+(T3-T4)]/2 and round-trip delay delta = (T4-T1)-(T3-T2). The protocol is inherently resistant to lost or duplicate packets and requires no reliable delivery.
The Reference ID (refid) field encodes the time source: for stratum 1, a left-justified zero-padded ASCII string (e.g., GPS, PPS, GOES); for stratum 2+ with IPv4, the upstream server's 4-octet IPv4 address; for stratum 2+ with IPv6, the first four octets of the MD5 hash of the IPv6 address. IANA maintains the authoritative list of stratum-1 reference identifiers.
The Stratum field is an 8-bit integer: 0 = unspecified/invalid (KoD packets), 1 = primary server synchronized directly to a reference clock, 2–15 = secondary servers via NTP, 16 = unsynchronized, 17–255 = reserved. Received stratum 0 is mapped to MAXSTRAT (16) internally; p.stratum values >= MAXSTRAT are mapped to 0 in transmitted packets.
The system process runs three sub-algorithms: the selection algorithm applies Byzantine fault detection to discard falsetickers and retain truechimers; the cluster algorithm uses statistical principles to select the most accurate subset; the combine algorithm computes a weighted-average final offset from the surviving truechimers. The synchronization distance LAMBDA = EPSILON + DELTA/2 represents the maximum error.
IANA has assigned NTP UDP port 123 and allocated IPv4 multicast address 224.0.1.1 and IPv6 multicast address ending :101 (prefix determined by scoping rules) for NTP use. Any non-allocated multicast address may also be used in addition to these.
IANA maintains the authoritative list of NTP Reference Identifiers (four-character ASCII strings identifying stratum-1 reference clock sources, e.g., GPS, PPS, GOES, WWV). ASCII strings beginning with 'X' are reserved for unregistered experimentation. IANA also maintains the NTP kiss code registry (stratum-0 Reference ID values used in KoD packets).
A crypto-NAK is returned when authentication fails on a received packet; it consists of a normal NTP header with a MAC of four zero octets. The receiving client MAY accept or reject the data in the message, and must decide whether to continue using the unauthenticated time values.
KoD DENY/RSTR packets can be spoofed by off-path attackers to cause clients to demobilize legitimate server associations, constituting a denial-of-service attack on time synchronization. Implementations should authenticate KoD packets where possible before acting on them.
NTP is vulnerable to replay attacks: replaying a client request packet causes the server to generate a fresh response with new T2 and T3 values, producing incorrect offset and delay at the client. This can be mitigated by zeroing the xmt state variable after computing offset and delay, ensuring a replayed response is rejected as bogus.
The symmetric key MD5 authentication scheme carried over from NTPv3 provides data origin authentication but does not prevent all forms of timing attack. The Autokey public key authentication scheme new to NTPv4 provides stronger security and is described separately in RFC 5906.
The peer dispatch table governs packet processing based on (association mode × packet mode): valid pairings dispatch to PROC (process the packet), while invalid ones result in DSCRD (discard), ERR (discard and demobilize symmetric passive association), FXMIT (stateless server response), MANY (manycast server response), NEWPS (mobilize symmetric passive), or NEWBC (mobilize broadcast client). ERR is a fatal protocol violation.
NTP defines three time formats: a 128-bit date format (64-bit signed seconds split into 32-bit Era Number and 32-bit Era Offset, plus 64-bit fraction resolving 0.05 attoseconds), a 64-bit timestamp format (32-bit unsigned seconds spanning 136 years, 32-bit fraction resolving 232 picoseconds), and a 32-bit short format (16-bit seconds, 16-bit fraction). The prime epoch is 0h 1 January 1900 UTC; a value of zero indicates unknown or unsynchronized time.
NTP extension fields consist of a 16-bit Field Type, a 16-bit Length (total octets including padding), a variable-length Value, and zero-padding to a 4-octet word boundary. The minimum field length is 16 octets. A MAC must always be present when an extension field is present.
The NTP packet header is a UDP datagram of 12 32-bit words (48 octets) in network byte order, containing LI (2 bits), VN (3 bits), Mode (3 bits), Stratum (8 bits), Poll (8 bits), Precision (8 bits), Root Delay (32 bits NTP short format), Root Dispersion (32 bits NTP short format), Reference ID (32 bits), and four 64-bit timestamps (Reference, Origin, Receive, Transmit). Optional extension fields and an optional MAC (32-bit Key Identifier + 128-bit MD5 digest) may follow.