The Network Time Protocol (NTP) is an application layer protocol in the TCP/IP protocol suite. NTP synchronizes the time among a set of distributed time servers and clients. NTP is built on the Internet Protocol (IP) and User Datagram Protocol (UDP). NTP messages are transmitted over UDP, using port 123.
NTP is evolved from the Time Protocol and the ICMP Timestamp message, but is specifically designed to maintain time accuracy and robustness.
In the NTP model, a number of primary reference sources, synchronized to national standards by wire or radio, are connected to widely accessible resources, such as backbone gateways. These gateways act as primary time servers. The purpose of NTP is to convey timekeeping information from these primary time servers to other time servers (secondary time servers). Secondary time servers are synchronized to the primary time servers. The servers are connected in a logical hierarchy called a synchronization subnet. Each level of the synchronization subnet is called a stratum. For example, the primary time servers are stratum 1, and the secondary time servers are stratum 2. Servers with larger stratum numbers are more likely to have less accurate clocks than those with smaller stratum numbers.
When multiple time servers exist on a network, use a clock selection algorithm to synchronize the stratums and time offsets of time servers. This helps improve local clock precision.
There is no provision for peer discovery or virtual-circuit management in NTP. Duplicate detection is implemented using processing algorithms.
Figure 1 illustrates the process of implementing NTP. Device A and Device B are connected through a wide area network (WAN). They both have independent system clocks that are synchronized through NTP.
In the following example:
Before Device A synchronizes its system clock to Device B, the clock of Device A is 10:00:00 am and the clock of Device B is 11:00:00 am.
Device B functions as an NTP server, and Device A must synchronize its clock signals with Device B.
It takes 1 second to transmit an NTP packet between Device A and Device B.
It takes 1 second for Device A and Device B to process an NTP packet.
The process of synchronizing system clocks is as follows:
Device A sends an NTP packet to Device B. When the packet leaves Device A, it carries a timestamp of 10:00:00 a.m. (T1).
When the NTP packet reaches Device B, Device B adds a receive timestamp of 11:00:01 a.m. (T2) to the packet.
When the NTP packet leaves Device B, Device B adds a transmit timestamp of 11:00:02 a.m. (T3) to the packet.
When Device A receives the response packet, it adds a new receive timestamp of 10:00:03 a.m. (T4) to the packet.
Device A uses the received information to calculate the following important values:
Roundtrip delay for the NTP packet: Delay = (T4 - T1) - (T3 - T2).
Relative offset between Device A and Device B clocks: Offset = [(T2 - T1) + (T3 - T4)]/2.
According to the delay and the offset, Device A re-sets its own clock to synchronize with the clock of Device B.