NTP Stratum Hierarchy
Run the NTP Stratum Hierarchy MicroSim Fullscreen
About This MicroSim
When your Pico W calls ntptime.settime(), the time it receives has traveled a long way. It starts at a stratum 0 reference, an atomic clock or a GPS satellite, and flows down through layers of servers. The stratum number counts how many steps a server is from the reference:
- Stratum 0: atomic clocks and GPS. They are the reference and are not on the internet.
- Stratum 1: servers wired directly to a stratum 0 clock, such as
time.nist.gov. - Stratum 2: servers that sync from stratum 1 over the internet. Most
pool.ntp.orgservers are stratum 2 or 3. - Your Pico W: the client. It asks for the time and never gives it out.
Each step adds a little error, but the biggest limit on your Pico's accuracy is the network delay between the Pico and the server. NTP measures four timestamps to estimate and cancel that delay:
| Timestamp | Recorded by | Moment |
|---|---|---|
| T1 | Pico clock | Request leaves the Pico |
| T2 | Server clock | Request arrives at the server |
| T3 | Server clock | Reply leaves the server |
| T4 | Pico clock | Reply arrives at the Pico |
The round trip is \( (T4 - T1) - (T3 - T2) \), and the correction to the Pico's clock is \( \frac{(T2 - T1) + (T3 - T4)}{2} \). The formula assumes the trip up and the trip back take the same time. They rarely do, so the error can be as large as half the round trip. In this MicroSim the Pico's clock starts 2.350 seconds slow, and the request takes 20 percent longer than the reply, so you can see the estimate land close to, but not exactly on, the true correction.
How to Use
- Click any box to read its role and typical accuracy in the yellow panel.
- Choose a server in Ask server. A dashed red line connects it to the Pico.
- Press Send request. A red packet travels from the Pico to the server and T1 and T2 appear. Press the button again to have the server reply (T3), and once more to bring the reply back (T4) and see the round trip, the correction, and the error limit.
- Drag Delay (one way) from 5 to 300 ms and send another request. Watch the error limit grow with the delay.
Iframe Embed Code
You can add this MicroSim to any web page by adding this to your HTML:
1 2 3 4 | |
Lesson Plan
Learning Objective
Students will understand how time flows from atomic clocks down through NTP servers to a Pico (Bloom: Understanding).
Grade Level
9-12 (Clocks and Watches with AI)
Duration
15 minutes
Prerequisites
- WiFi connection on the Pico W (Chapter 14)
- UTC and epochs (Chapters 6 and 14)
Activities
- Trace the path (3 min): Students click from the atomic clock down to the Pico and write one sentence about each stratum.
- Step through an exchange (5 min): With a 40 ms delay, students step through a request and record T1 to T4. They verify the round-trip formula by hand.
- Change the delay (4 min): Students repeat the exchange at 10 ms and at 300 ms and compare the error limits. What matters more for the Pico's accuracy: the server's stratum or the network delay?
- Discuss (3 min): Why is a stratum 2 server close to you often a better choice than a stratum 1 server on the other side of the world?
Assessment
- What does stratum 2 mean? (Two steps from a reference clock.)
- If the round trip is 100 ms, what is the worst-case error of the sync? (About 50 ms.)
- Explain why the Pico records T1 and T4 with its own clock, but T2 and T3 come from the server's clock.
References
- Network Time Protocol - Wikipedia; covers strata and the clock synchronization algorithm.
- RFC 5905: Network Time Protocol Version 4 - The NTP specification, including the T1 to T4 offset and delay formulas.
- NIST Internet Time Service - The stratum 1 servers behind
time.nist.gov. - NTP Pool Project - The volunteer servers behind
pool.ntp.org. - vis-network documentation - The graph library used by this MicroSim.