The NTP protocol

hatzisn

Well-Known Member
Licensed User
Longtime User
Yesterday I watched a video about the NTP protocol and I was completely thrilled by its simplicity and cleverness. I am sure you all or most of you know it but I am mentioning this in case someone does not. The NTP protocol is the protocol with which our computers and devices synchronize their time with NTP servers.

Let's see the plain case. If you send a request to any server at t0 then it will take ΔΤ1 for the packet to go to the server and ΔΤ2 for the server to report to you the time. It is obvious that with this simple case you cannot synchronize at all the two machines.

And here comes the NTP protocol which utilizes four times for synchronization (t0, t1, t2, t3). Here is how it works. The sender marks in the packet the time t0 it sends the request (f.e. 8:29:58). When the NTP server receives the request it marks the t1 which is the time it received it (f.e. 8:30:02). Since it serves a lot of requests it will not respond immediately but will respond after a short period and it will mark in the packet the time t2 which is the time it begins sending the response to the request (f.e. 8:30:04). The packet travels through the Internet and let's say it is received at the sender at the time t3 (f.e. 8:30:06).

Now the sender does the calculations:

1) t3 and t0 are my times so the whole time it took from sending the request to receiving it it was (t3-t0), This time includes the going time, the processing time and the returning time.
2) t2 and t1 are NTP server times so the time it took NTP server to respond was (t2-t1)
3) In order to calculate the travelling time (going and returning) it is obvious that it is ΔΤ3 = (t3-t0) - (t2-t1). Now the travelling time depends on the nodes the information gets bettween me (the sender) and the NTP server and the same is valid for the return path. According to the way internet works these paths may not be the same so a wise thing to do would be to take the mean time for each root, that is ΔΤ3 / 2.
4) So the time it took from me to get to the server is ΔΤ3 / 2, so when time at me was t0 the time at the server was tS = t1 - (ΔΤ3 / 2).
5) So in order to synchronize my time to the NTP server I will have to add to my time ΔΤ4 = tS-t0.

Applying all these to the arithmetic values we have set then it would be:

1) (t3-t0) = 8 sec
2) (t2-t1) = 2 sec
3) ΔΤ3 = (t3-t0) - (t2-t1) = 6 sec --> ΔΤ3 / 2 = 3 sec
4) tS = t1 - (ΔΤ3 / 2) = (8:30:02)-(0:00:03) = (8:29:59)
5) ΔΤ4 = tS-t0 = (8:29:59)-(8:29:58) = (0:00:01). So I will have to add to my time one second to synchronize with the NTP server.

Easy, plain and clever.

According to the protocol the synchronization occurs a lot of times during the time the computer is open and the clocks can get synchronized up to milliseconds accuracy.
 
Last edited:

emexes

Expert
Licensed User
According to the way internet works these paths may not be the same so a wise thing to do would be to take the mean time for each root, that is ΔΤ3 / 2.
4) So the time it took from me to get to the server is ΔΤ3 / 2

The time it took from you to the server is *approximately* ΔΤ3 / 2.

It's likely close to that, but could be anywhere between 0 and ΔΤ3.

On the bright side, we do reliably know that ΔΤ3 is the upper limit, and happily it's typically eg less than 1/100th of a second to a local NTP server here.

1668587137383.png
 

emexes

Expert
Licensed User
On the bright side, we do reliably know that ΔΤ3 is the upper limit, and happily it's typically eg less than 1/100th of a second to a local NTP server here.

cf a tad longer to US NIST:

1668588666476.png


although that reminds me that light through fibre is about 2/3rds speed of light through vacuum = 200,000 km/second, so the travel time between here and the NIST server in Boulder, Colorado is at least 70 milliseconds (probably more, assuming the cable passes via Hawaii) and thus ΔΤ3 between 70 and 140 ms.

1668589002531.png
 
Last edited:

hatzisn

Well-Known Member
Licensed User
Longtime User
The time it took from you to the server is *approximately* ΔΤ3 / 2.

It's likely close to that, but could be anywhere between 0 and ΔΤ3.

On the bright side, we do reliably know that ΔΤ3 is the upper limit, and happily it's typically eg less than 1/100th of a second to a local NTP server here.

Approximatelly is correct.
 

Magma

Expert
Licensed User
Longtime User
For example check that:

at the right side... Your clock is off by:... i think they had an API...

...may be that...
 

rabbitBUSH

Well-Known Member
Licensed User
GEE isn't it FANTASTIC - All Of That just to deal with something that people-kind sucked out it's thumb because plain old natural-vegetable-time-light-and-dark is too bizarre for them all to deal with without chopping it up into ordered lists.

There again - some say - mathematicals is the basis of all quanta. (So I went for the masters degree in fine arts a vegetable time IDE)
 

hatzisn

Well-Known Member
Licensed User
Longtime User
For example check that:

at the right side... Your clock is off by:... i think they had an API...

...may be that...

Great resource the second API. Thank you. The API though will report the time as it is on the server after the return journey so you will be off something again.
 
Top