What is NTP?
NTP keeps the clocks of computers, phones and servers in step with the real time, usually to within a few milliseconds over the internet. Your device asks a time server, measures how long the question took, and corrects its own clock.
Correct time matters more than it seems. HTTPS certificates have start and end dates, logins use time-based codes, logs from many servers must line up, and payments carry timestamps. A clock that is far off can quietly break all of these.
Think of it like this. Imagine calling a friend to set your watch. You note when you asked, they say the time, and you note when you heard it. If the call took two seconds there and back, you know their answer is about one second old, so you add that before setting your watch.
Step by step
Clock sync
4 stepsYour laptop's clock is 250 ms slow. Two quick questions to a time server measure the error and the network delay.
Clock sync
4 stepsYour laptop's clock is 250 ms slow. Two quick questions to a time server measure the error and the network delay.
- 1
Ask the time
Stamp T1 on the way out
The laptop writes its own clock reading, T1, into a 48-byte request and sends it to the time server on UDP port 123.
- 2
Server stamps twice
T2 on arrival, T3 on departure
The server notes when the request arrived (T2) and when its reply leaves (T3), and copies T1 back. When the reply lands, the laptop notes T4 by its own clock.
- 3
Do the math
Offset 250 ms, delay 30 ms
Round trip delay is the total time minus the server's time: (T4 - T1) - (T3 - T2) = 31 - 1 = 30 ms. Clock offset is the average of the two one-way gaps: ((T2 - T1) + (T3 - T4)) / 2 = (265 + 235) / 2 = 250 ms. So the laptop is 250 ms slow.
- 4
Check and adjust
More samples, then a gentle fix
One sample can be skewed by a slow packet, so the client asks a few times and keeps the sample with the lowest delay. Small errors are fixed by running the clock slightly fast for a while (slewing), so time never jumps backwards.
Clock far off
4 stepsA laptop with a dead clock battery thinks it is 2020, so every HTTPS certificate looks invalid until NTP fixes the date.
Clock far off
4 stepsA laptop with a dead clock battery thinks it is 2020, so every HTTPS certificate looks invalid until NTP fixes the date.
- 1
HTTPS fails
Certificate not valid yet
Omar's old laptop lost its clock setting and woke up on 1 January 2020. The site's certificate is valid from September 2026, so by the laptop's clock it is not valid yet, and the browser shows a clock error.
- 2
Ask a time server
Offset of almost seven years
The laptop asks the time server. The offset comes out at nearly seven years, far too big to fix by running the clock slightly fast.
- 3
Step the clock
Jump to the right time
For a large error the time service sets the clock in one jump, called a step. Many clients only do this at start-up or with your approval, to avoid sudden jumps later.
- 4
Retry works
Certificate dates now fit
With the right date, the certificate is inside its valid window and the page loads normally.
Myths and mix-ups
- NTP does not just copy the server's time; it measures the network delay and corrects for it.
- A clock set from NTP is not normally made to jump; small errors are fixed by gently speeding up or slowing down the clock.
- Your computer's built-in clock is not accurate on its own; it can drift by seconds a day without NTP.
- A wrong clock does not only affect the time on screen; it can break HTTPS, logins with one-time codes and backups.
Try it yourself
Run these on your own computer to see NTP at work.
Sync status (Windows)
w32tm /query /statusShows the time source, stratum and when the clock last synced.
Measure your offset (macOS)
sntp $(awk '/server/{print $2}' /etc/ntp.conf)Asks your Mac's configured time server and prints how far off your clock is, in seconds.
Sync status (Linux with chrony)
chronyc trackingSystem time shows the current offset. Root delay is the round trip to the reference clock.
Sync status (Linux with systemd)
timedatectl timesync-statusShows the server, the stratum, the offset and the delay.
NTP at a glance
- Layer
- Application (7)
- Port
- UDP 123
- Message size
- 48 bytes of NTP data
- Accuracy
- Milliseconds over the internet, better on a local network
- Stratum
- 1 is wired to a reference clock, up to 15
- Timestamps
- Four per exchange: T1, T2, T3, T4
- Current version
- NTPv4, 2010 (RFC 5905)
- Secure version
- Network Time Security (RFC 8915)
Defined inRFC 5905RFC 8915
Header fields
What NTP puts in its messages, with example values from the stories above.
NTP
- Leap indicator
0 (no warning)Warns of a leap second at the end of the day. 3 would mean the clock is not synced.- Version
4- Mode
3 (client)3 is a client asking, 4 is a server answering.- Stratum
0 (unspecified)Distance from a reference clock. Stratum 1 is wired to GPS or an atomic clock, stratum 2 syncs from a stratum 1, and so on.- Poll interval
6 (64 s)- Reference ID
(empty)- Origin timestamp (T1)
10:00:00.000 (T1)Copied from the client's request, so the client can match the reply and use T1 in the math.- Receive timestamp (T2)
10:00:00.265 (T2)When the request reached the server, by the server's clock.- Transmit timestamp
10:00:00.000 (T1)T1: when the request left, by the laptop's own clock.- Root delay
0.0122 sRound trip from this server up to the reference clock. Adds to how much the answer can be trusted.
Test yourself
Which port does NTP use?
Questions people ask
What is NTP and why is it important?
NTP is the protocol devices use to set their clocks from time servers. Correct time keeps certificates, logins, logs and payments working.
What port does NTP use?
UDP port 123 for both requests and replies. Network Time Security adds a key setup step over TLS before that.
How accurate is NTP?
Over the internet, usually within a few milliseconds. On a good local network it can be better than one millisecond.
Why does my computer say my clock is behind?
The browser checked a certificate and your clock falls outside its valid dates. Turn on automatic time in your settings so NTP can fix it.
What is the difference between NTP and SNTP?
SNTP is a simpler client that asks once and sets the clock. Full NTP keeps measuring several servers and steers the clock smoothly over time. They use the same packets.