opyeb totplab

Clock drift and the ±2 step window: where to look when a code fails

When a code fails, the cause is usually the clock, not the secret. Knowing where it drifts tells you how many seconds to fix.

2026-11-29 · about 6 min

Why codes drift apart

TOTP advances its counter every 30 seconds. A few seconds of difference between the authenticator and the server is enough for the two sides to compute different steps.

At the exact boundary — 12:00:29 turning into 12:00:30 — the app may show the previous step while the server already reads the next one.

What happens at a boundary

One step covers 0–29 seconds and the next covers 30–59. A one-second difference at the boundary becomes a 30-second difference in steps.

That is why most servers accept the previous and the next step as well as the current one. This is the usual ±1 window.

±1 versus ±2

±1 tolerates up to 30 seconds of error and ±2 up to 60 seconds. A wider window is friendlier to users but leaves a code usable for longer.

Sensitive services often use ±1 and general services ±2. This tool compares a ±2 window so you can measure the error at the wide end.

Measuring the error in seconds

Multiply the matched offset by the period. An offset of +1 with a 30-second period means the device clock is 30 seconds ahead (or the server 30 seconds behind).

An offset of −2 means the code was produced two steps earlier, roughly 60 seconds late. Fix the clock and check again.

Getting the clock right

Phones and computers normally synchronise with network time automatically. Automatic time can be off, and old sleeping devices or virtual machines can drift by minutes.

Turn on automatic time, resynchronise, and check the code again. If it still fails, use the ±2 verification here to measure the actual offset.

How the window works for HOTP

HOTP uses a counter instead of time. Servers usually accept only counters greater than the last successful one, which blocks replays.

Widening the window for HOTP therefore widens what can be replayed. A larger verification window always means weaker security.

What a wider window buys and what it costs

A wider window lets a code that arrives late still pass, which genuinely helps users on slow networks or with a slightly off clock.

On the other hand it lengthens the time in which an intercepted code can be replayed. Services therefore pick a window between convenience and replay risk, and report success back to the device so it does not reuse a code.

What to record when you debug

Never record the code itself. Record the time, the step number, the offset, the algorithm and the digit count — that is enough.

This page shows the step and the offset, so copying those numbers lets you reproduce the situation later.

Questions in this article

Is the previous code dead after 30 seconds?

It depends on the server. With a ±1 window the previous step still passes. Reusing the same code twice should be avoided everywhere.

How many seconds should I correct?

Exactly the drift reported. An offset of +1 with a 30-second period means the clock is 30 seconds fast — correct it or resynchronise.

Can the window be wider than ±2?

It is not recommended. A wider window keeps codes valid longer and exposes them to replay. This tool stops at ±2 because it is a diagnostic.

An example secret is already loaded. Replace it with yours and the code changes on the spot.

Open the workbench
← All guides