Structure of the NTP Data packet


0    1      4         7          15        23                    31
Cryptosum LI VN Mode Strat Poll Prec
LI = leap indicator
VN = version number
Strat = Stratum (0-15)
Poll = poll intervall
Prec = Precision
Root Delay
Root Dispersion
Reference Identifier
Reference Timestamp Seconds (32), Fraction (32)
Originate Timestamp Seconds (32), Fraction (32)
Receive Timestamp Seconds (32), Fraction (32)
Transmit Timestamp Seconds (32), Fraction (32)
Ext. Field 1 Key Identifier (optional)
Ext. Field 2 Message Digest (optional)
Authenticator (Optional) Key/Algorithm Identifier
Message Hash (64 or 128)


The header fields of the NTP message are as follows:
LILeap Indicator (2 bits)
This field indicates whether the last minute of the current day is to
have a leap second applied. The field values follow:
0: No leap second adjustment
1: Last minute of the day has 61 seconds
2: Last minute of the day has 59 seconds
3: Clock is unsynchronized>
VNNTP Version Number (3 bits) (current version is 4).
ModeNTP packet mode (3 bits) The values of the Mode field follow:
0: Reserved
1: Symmetric active
2: Symmetric passive
3: Client
4: Server
5: Broadcast
6: NTP control message
7: Reserved for private use
Stratum Stratum level of the time source (8 bits) The values of the
Stratum field follow:
0: Unspecified or invalid
1: Primary server
2–15: Secondary server
16: Unsynchronized
17–255: Reserved
PollPoll interval (8-bit signed integer)2 value of the
maximum interval between successive NTP messages, in seconds.
Precision Clock precision (8-bit signed integer) The precision of the
system clock, in log2 seconds.
Root Delay The total round-trip delay from the server to the primary
reference sourced. The value is a 32-bit signed fixed-point
number in units of seconds, with the fraction point between
bits 15 and 16. This field is significant only in server messages.
Root Dispersion The maximum error due to clock frequency tolerance. The
value is a 32-bit signed fixed-point number in units of
seconds, with the fraction point between bits 15 and 16.
This field is significant only in server messages.
Reference Identifier For stratum 1 servers this value is a four-character
ASCII code that describes the external reference source
(refer to Figure 2). For secondary servers this value
is the 32-bit IPv4 address of the synchronization source,
or the first 32 bits of the Message Digest Algorithm 5
(MD5) hash of the IPv6 address of the synchronization source.

Code External Reference Source
-------------------------------------------------------
LOCL uncalibrated local clock
CESMCalibrated Cesium clock
RBDMcalibrated Rubidium clock
PPScalibrated quartz clock or other pulse-per-second source
IRIGInter-Range Instrumentation Group
ACTSNIST telephone modem service
USNOUSNO telephone modem service<
PTBPTB (Germany) telephone modem service
TDFAllouis (France) Radio 164 kHz
DCFMainflingen (Germany) Radio 77.5 kHz
MSFRugby (UK) Radio 60 kHz
WWVFt. Collins (US) Radio 2.5, 5, 10, 15, 20 MHz
WWVBBoulder (US) Radio 60 kHz
WWVHKauai Hawaii (US) Radio 2.5, 5, 10, 15 MHz
CHUOttawa (Canada) Radio 3330, 7335, 14670 kHz
LORCLORAN-C radionavigation system
OMEGOMEGA radionavigation system
GPSGlobal Positioning Service

NTPv4 Extension Fields
Field Length Field Type
Extension Field
(padded to 32-bit boundary)
Last field padded to 64-bit boundary
NTP V3 and V4
NTP V4 only
authentication only


NTP Timestamp
NTP timestamp format (64 bits) :
Seconds (32) Fraction (32)
Seconds and Fractions since 01.01.1900


The time synchronization between Client and Server works as follows:
Now you get 4 timestamps:

CientConnection Server
Timestamp 1 Client-Server Timestamp 2
Timestamp 4 Server-Client Timestamp 3

From these four timestamps the system can calculate two values:

These values are calculated as follows:
Offset = (t2 - t1) + (t3 - t4)
-----------------
2
Delay = (t4 - t1) - (t3 - t2)
Here you can see that NTP averages the Delay  because it assumes that
 the trip of the packet is the same in both directions,
that means differences influence the Offset  as an error.



In local networks the round-trip delay is only a small part of the 
offset and therefor the offset calculation is already precise.



In bigger networks the offsets and delays are filtered more often, to compensate the delay variations.
The offset is calculated from the packet with the smallest delay out of the last eight packets.



Additionally an other value is calculated from the same packets:

The " Dispersion " value, an averaged value of the offset deviation from the eight last data packets to the actual offset. The offsets with a smaller delay are weighted more.