Names, time and addressesApplicationRFC 5905

NTP: keeping clocks right

How computers agree on the time to within a few milliseconds.

Ports and use: UDP 123

In one sentenceNTP compares your clock with a better one, works out the delay, and adjusts yours.

Think of it like thisIt is like asking a friend with a perfect watch what time it is and subtracting the time the message took to travel.

Watch it happen

3 steps and 2 byte-by-byte decodes. Use the buttons or the arrow keys. Hover or focus a field to find its bytes.

  1. Your laptop
  2. NTP server
  1. Request with a timestampYour laptop to NTP server
  2. Reply with three timestampsNTP server to Your laptop
  3. Work out the offsetYour laptop to Your laptop

Step 1 of 3 Request with a timestamp

Your laptop → NTP server

The laptop sends 48 bytes over UDP, noting its own time T0 when it leaves.

NTP request 48 bytes

23 00 00 00 00 ×12 00 ×24 ee a6 48 b8 40 00 00 00

FieldBytesWhat it means
Leap, version, mode23Binary 00 100 011: no leap-second warning, version 4, mode 3 which means "client".
Stratum, poll, precision00 00 00Unused in a request, so zero.
Root delay, dispersion, reference ID00 ×12Server-side details. Zero in a request.
Reference, origin and receive timestamps00 ×24Not used by a simple client, so zero.
Transmit timestamp (T1)ee a6 48 b8 40 00 00 00The time on the laptop's clock when the request left: seconds since 1900 plus a fraction. The server will copy this back.

Step 2 of 3 Reply with three timestamps

NTP server → Your laptop

The server adds when it received the request (T1) and when it replied (T2), and copies back T0.

NTP reply 48 bytes

24 02 06 ec 00 00 0a 3d 00 00 0f 1c c0 00 02 01 ee a6 48 9a 43 12 70 00 ee a6 48 b8 40 00 00 00 ee a6 48 b8 43 12 70 00 ee a6 48 b8 43 1c 44 00

FieldBytesWhat it means
Leap, version, mode24Binary 00 100 100: no warning, version 4, mode 4 which means "server".
Stratum022: this server gets its time from a stratum 1 server, which has a clock of its own such as GPS or an atomic clock.
Poll066: asks clients to check about every 2^6 = 64 seconds.
Precisionecec is -20 as a signed number: the clock is accurate to about 2^-20 seconds, around a microsecond.
Root delay00 00 0a 3dTotal round-trip delay to the original time source.
Root dispersion00 00 0f 1cTotal error that could build up along the chain to the source.
Reference IDc0 00 02 01192.0.2.1: the upstream server this one is synchronised to.
Reference timestampee a6 48 9a 43 12 70 00When the server last set its own clock.
Origin timestamp (T0)ee a6 48 b8 40 00 00 00A copy of the laptop's transmit time from the request.
Receive timestamp (T1)ee a6 48 b8 43 12 70 00When the server received the request.
Transmit timestamp (T2)ee a6 48 b8 43 1c 44 00When the server sent this reply.

Step 3 of 3 Work out the offset

Your laptop

On arrival the laptop notes T3. Round-trip delay = (T3 - T0) - (T2 - T1). Clock offset = ((T1 - T0) + (T2 - T3)) / 2. It then speeds up or slows down its clock slightly to close the gap.

Where you meet it

  • Making log files from many servers line up in time order.
  • Certificates, tokens and one-time codes, which stop working if the clock is wrong.
  • Banking and trading systems that must timestamp events precisely.

Common mistakes

  • Letting servers drift. A few minutes of drift can break HTTPS, login tokens and Kerberos.
  • Using only one NTP server. Use at least three so a wrong one can be spotted.
  • Setting the time by hand on virtual machines that then drift again.
  • Forgetting that UDP 123 must be open on the firewall.

Try it yourself

Run these on your own computer and compare the output with the lesson above.

  • timedatectl statusLinux: shows whether your clock is synchronised.
  • chronyc trackingShows the current offset if chrony is installed.
  • w32tm /query /statusWindows: the same check.

Back to Network Lab

Addresses and values in the examples are made up for teaching (the 203.0.113.x range is reserved for documentation). Real traffic carries more options and details. Check the standard named above for the full rules.