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 (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.
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.
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.
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.
// 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);
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).
| Stratum | Description | Accuracy |
|---|---|---|
| Stratum 0 | Atomic clocks, GPS, radio signals | Nanoseconds |
| Stratum 1 | Servers connected to reference | Microseconds |
| Stratum 2 | Public NTP servers | 1–10 ms |
| Stratum 3 | Local organization servers | 10–50 ms |
| Stratum 4+ | Client devices | up to 100 ms |
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 (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.
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.
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.
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.
// 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
}
}
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.
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
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.
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.
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.
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.
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
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.
Read also