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.
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: