Network Time Protocol (NTP) is an application-layer protocol within the TCP/IP suite used to synchronize clocks between distributed time servers and clients; the service typically operates on UDP port 123. NTP employs a hierarchical structure known as "Stratum" levels: servers that synchronize directly with authoritative time sources (such as atomic clocks or GPS) are designated as Stratum 1 (primary time servers); Stratum 2 servers obtain time from Stratum 1 servers, and so on, with clock accuracy decreasing as the stratum level increases.
NTP utilizes a client-server model for time synchronization. The client sends an NTP request packet and records the departure time (t1); the server records the arrival time (t2) upon receipt and the departure time (t3) when sending the response; the client records the arrival time (t4) upon receiving the response. Using these four timestamps, the time offset between the client and the server can be calculated using the formula: offset = [(t2 - t1) - (t4 - t3)] / 2; the client then adjusts its local clock accordingly to achieve synchronization. The NTP synchronization subnet consists of primary time servers, secondary time servers, and clients, forming a hierarchical master-slave structure capable of automatic reconfiguration in the event of server or network path failures.
