NTP — what it is, time protocol and synchronization in applications

Author: IT Sectr Published: 2026-07-14 Reading time: 9 min

NTP (Network Time Protocol) is a network time synchronization protocol that provides accuracy down to milliseconds on local networks and tens of milliseconds over the global network. Developed by David Mills in 1985, the protocol is used in all modern operating systems, mobile devices, and network equipment to synchronize internal clocks with the UTC reference time. According to the NTP Pool Project (2026), over 4 billion devices perform NTP requests daily for synchronization.

Key Takeaways

  • NTP is a time synchronization protocol over a network, accuracy from 1 ms (LAN) to 50 ms (WAN)
  • Stratum hierarchy — a level system (stratum 0–16), where stratum 0 is the reference atomic clock
  • Drift correction — NTP does not just set the time, it adjusts the clock frequency for continuous accuracy
  • SNTP — a simplified version of NTP for resource-constrained devices, used in IoT and Android
  • Security — NTPv4 supports authentication via symmetric keys and NTS (Network Time Security)

What is NTP?

NTP (Network Time Protocol) is a network protocol designed for accurate synchronization of a computer's internal clock with a reference time source over a packet-switched network. Described in RFC 5905 (NTPv4), the protocol uses a hierarchical system of servers, where each level is called a stratum. An NTP client sends requests to a server, measures the packet round-trip time (RTT), and calculates the offset of its own clock relative to the reference time. The correction algorithm accounts not only for a single offset but also for the drift of the clock generator, allowing accuracy to be maintained over long periods without repeated requests.

History of NTP development

The protocol was developed by David Mills in 1985 for the ARPANET. The first specification (RFC 958) described a simple synchronization algorithm with accuracy up to 100 ms. NTPv3 (RFC 1305, 1992) added a filtering algorithm and improved delay processing. NTPv4 (RFC 5905, 2010) — the current version — includes IPv6 support, automatic server configuration, and protection against attacks via Network Time Security (NTS). Over 40 years, the protocol has evolved from a research project to an infrastructure standard, without which financial transactions, telecommunications, and mobile networks would be impossible.

How NTP works

The operating principle of NTP is based on measuring packet travel time over the network. The client sends a request with a timestamp T1 (local send time). The server receives the request at time T2 (server time), generates a response with timestamp T3, and sends it. The client receives the response at time T4. Using all four timestamps, the client calculates the offset = ((T2 - T1) + (T3 - T4)) / 2 and the delay = (T4 - T1) - (T3 - T2). If the delay exceeds 1 second, the result is considered unreliable — this protects against overloaded or unstable channels.

Clock drift correction

Simply setting the correct time is not enough — the quartz oscillator on a device constantly drifts (gains or loses time) due to temperature, aging, and voltage. NTP solves this problem using the PLL (Phase-Locked Loop) algorithm: it does not forcibly set the time, but adjusts the clock speed. If the device is 0.1 seconds per hour fast, NTP slows down the system clock until the drift is compensated. This approach allows synchronization every few hours on stable networks, rather than every 30 seconds.

cpp
// Simplified NTP algorithm schema
struct NTPPacket {
    uint8_t flags;      // LI, VN, Mode
    uint8_t stratum;    // server stratum level
    uint32_t refTimestamp;  // reference timestamp
    uint32_t originTimestamp; // T1
    uint32_t recvTimestamp;   // T2
    uint32_t xmitTimestamp;   // T3
};

// Calculate offset and delay
double offset = ((t2 - t1) + (t3 - t4)) / 2.0;
double delay = (t4 - t1) - (t3 - t2);

Strata — NTP hierarchy

The entire NTP system is organized into a hierarchy, where each level is called a stratum. Stratum 0 is the reference clock: atomic clocks, GPS receivers, or WWVB radio signals. These devices are not directly connected to the network. Stratum 1 — servers directly connected to the reference clocks. Stratum 2 receives time from stratum 1, stratum 3 from stratum 2, and so on up to stratum 15. The higher the stratum number, the potentially lower the accuracy — each level adds a slight delay and error. Stratum 16 means that time is unavailable (not synchronized).

StratumDescriptionAccuracy
Stratum 0Atomic clocks, GPS, radio signalsNanoseconds
Stratum 1Servers connected to referenceMicroseconds
Stratum 2Public NTP servers1–10 ms
Stratum 3Local organization servers10–50 ms
Stratum 4+Client devicesup to 100 ms

Choosing a server by stratum

For mobile devices, stratum 2 servers are optimal — there are enough of them and they provide a good balance between accuracy and availability. For example, pool.ntp.org is a pool of thousands of servers worldwide, automatically balancing the load. For Android applications, it is not recommended to use stratum 1 directly: firstly, it creates excessive load on primary servers, and secondly, a mobile device only needs 10–50 ms accuracy, which stratum 2 provides. In corporate networks, a local stratum 3-4 server is set up that synchronizes with an external stratum 2.

SNTP — simplified version of NTP

SNTP (Simple Network Time Protocol, RFC 4330) is a simplified implementation of NTP for resource-constrained devices: microcontrollers, IoT sensors, and mobile applications that do not require high accuracy. Unlike full NTP, SNTP does not perform multi-server filtering, does not analyze clock drift, and does not use complex PLL algorithms. An SNTP client sends a request, receives a response, and sets the time once. SNTP accuracy is 10–100 ms depending on the network — this is sufficient for the vast majority of mobile scenarios, except financial transactions.

When to use SNTP instead of NTP

SNTP is suitable for Android applications that simply need to get the current time from a server without maintaining continuous synchronization. For example, an app shows the server time at login or synchronizes once a day. Full NTP is required for server systems, telecommunications equipment, financial platforms, and distributed databases where constant accuracy and drift monitoring are critical. For mobile development, SNTP is sufficient — the built-in Android time service uses it for periodic synchronization with Google servers.

NTP implementation in Android

In Android applications, obtaining accurate time via NTP is needed when the system time may be changed by the user or differs from the real time due to lack of network. Android does not have a built-in public NTP client — developers use the Apache Commons Net SntpClient library or third-party solutions. In 2022, Google added an internal SntpClient class to the Android API (via Google Play Services), but it requires configuration and is not documented for general use. An alternative approach is to request time via a REST API that returns the server timestamp in the response body.

Example of SNTP client implementation

A basic SNTP implementation on Android consists of sending a UDP packet to an NTP server (e.g., pool.ntp.org), parsing the response, and extracting the transmit timestamp (T3). The code must handle network timeouts and parsing errors — in a real application, this operation is performed on a background thread, and the result is cached until the next synchronization. The Apache Commons Net library provides a ready-made NTPUDPClient class that can be used in Android with minimal modifications by adding the dependency to build.gradle.

kotlin
// Get NTP time via Apache Commons Net
fun getNtpTime(server: String = "pool.ntp.org"): Date? {
    return try {
        val client = NTPUDPClient()
        client.setDefaultTimeout(5000)
        val info = client.getTime(InetAddress.getByName(server))
        client.close()
        Date(info.getMessage().getTransmitTimeStamp().getTime())
    } catch (e: Exception) {
        null
    }
}

NTP accuracy and influencing factors

The accuracy of NTP depends on several factors: network delay (RTT), channel stability, server load, and the quality of the local clock generator. On a local network with less than 1 ms delay, NTP achieves accuracy of 0.1–1 ms. Over the internet with 10–50 ms delay, accuracy drops to 10–50 ms. More important than single-shot accuracy is stability: if the delay varies (jitter), NTP needs more time to compute a reliable offset. For mobile devices, the main instability factor is switching between Wi-Fi and mobile networks, where the delay can change by an order of magnitude.

Recommendations for mobile development

For Android applications sensitive to accurate time, it is recommended to: use multiple NTP servers and select the one with the lowest delay; avoid synchronizing during network switches; cache the last obtained time and adjust it via System.currentTimeMillis. For games and real-time applications (NTP is not suitable here due to network latency) — use server time passed in each request. In financial applications, always check the discrepancy with the server — if the difference exceeds 5 seconds, block the operation as potentially unsafe.

Frequently Asked Questions

What is NTP and why is it needed?

NTP (Network Time Protocol) is a clock synchronization protocol over the internet. It is needed to align time on devices with the UTC reference. Without NTP, computer clocks drift by seconds per day due to quartz oscillator drift, which is critical for financial transactions, logging, and security.

How is the NTP hierarchy structured?

The NTP system uses levels — strata: stratum 0 (atomic clocks and GPS), stratum 1 (servers connected to reference), stratum 2 (public NTP servers), stratum 3–4 (local servers), stratum 5–15 (clients). The higher the stratum, the greater the potential error. Stratum 16 means time is not synchronized.

How does NTP differ from SNTP?

SNTP is a simplified version of NTP for resource-constrained devices. It does not filter servers, analyze clock drift, or use PLL. SNTP is suitable for mobile applications where 10–100 ms accuracy is sufficient. Full NTP is needed for servers, telecommunications equipment, and fintech systems.

How to get accurate time via NTP in Android?

Use the Apache Commons Net library with the NTPUDPClient class. Send a request to pool.ntp.org, get the response, and extract the Transmit Timestamp. Alternatively, use the REST API of your server, which returns the server time in the Date header or in the response body as a Unix Timestamp.

Why is time synchronization important on mobile devices?

Without NTP synchronization, the system time on a device can differ by minutes or hours. This disrupts push notifications, SSL certificate validation, logs, task schedulers, and cryptographic protocols. In financial applications, a discrepancy of more than 5 seconds is considered a security threat.

Summary

  • NTP is a network time synchronization protocol providing accuracy from 1 ms (LAN) to 50 ms (WAN) via a stratum 0–16 hierarchy
  • Drift correction — NTP does not just set the time, it adjusts the clock frequency via PLL, maintaining accuracy for hours between synchronizations
  • Stratum hierarchy — each level (stratum) adds potential error; for mobile devices, stratum 2 servers like pool.ntp.org are optimal
  • SNTP — a simplified version of NTP for IoT and Android, without filtering and PLL; 10–100 ms accuracy is sufficient for most scenarios
  • Android implementation — via Apache Commons Net (NTPUDPClient) or REST API with server timestamp; no built-in public NTP client exists on the platform
  • Security — NTPv4 supports Network Time Security (NTS) to protect against response spoofing; critical for financial and enterprise applications
  • Accuracy factors — RTT, jitter, network switching; mobile apps need 10–50 ms accuracy, but critical operations require checking the discrepancy with the server

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also