Understanding Time Drift in Classic TOTP Tokens

Time‑based One‑Time Passwords (TOTP) — defined in RFC 6238 — are widely used for second‑factor authentication. A TOTP value is generated by applying a cryptographic hash to a shared secret and a time counter, typically derived by dividing the current Unix time by a step interval (usually 30 seconds). For the server to verify the code successfully, both the TOTP generator (app or hardware token) and the server must have closely synchronized clocks.

What Is Time Drift?

“Time drift” occurs when the clock inside a TOTP token (especially hardware tokens with independent oscillators) deviates from the server’s clock. Without compensation, a drift of even tens of seconds can cause valid codes to be rejected because they no longer match the server’s expected value. Time drift is an inherent issue in any electronic clock or RTC chip—including those in hardware TOTP tokens—where the internal oscillator’s frequency deviates slightly from its ideal value due to manufacturing tolerances, aging, and environmental factors like ambient temperature. In real-world devices, this drift typically results in a time discrepancy of ±2 minutes per year, though the actual value can vary significantly with temperature fluctuations.  

How RFC 6238 Recommends Handling Time Drift

RFC 6238 acknowledges that clocks may differ and recommends several mechanisms for handling drift:

  • Validation window: Servers SHOULD accept OTPs not only for the current time step (T) but also for a number of adjacent steps before and after (e.g., T−1, T+1). This compensates for modest clock skew between client and server.
  • Resynchronization logic: If a token consistently generates OTPs ahead or behind the server’s time, the server can record the offset in time steps once a valid OTP is detected. Future validations can then adjust for this drift, improving reliability without compromising security.
  • Limits and recovery: The server should define a maximum allowable drift. If the token’s drift exceeds this limit, authentication should fail, and the user may need to perform explicit resynchronization or re-enrollment to realign the token with the server.

Example: How Microsoft Entra ID Handles Time Drift

Microsoft’s identity platform (Microsoft Entra ID) implements its own time‑drift compensation for OATH TOTP tokens, both during token activation and subsequent sign‑ins. According to Microsoft documentation:

  • For tokens with a 30‑second refresh interval, Entra ID allows a drift of ±1 day during activation and ±1 minute during authentication. (Microsoft Docs)
  • For tokens with a 60‑second refresh interval, the server allows a drift of ±2 days during activation and ±2 minutes during authentication. (Microsoft Docs)

During authentication, Entra ID automatically checks the OTP across the allowed window. If a code falls within the acceptable drift, the server accepts it and records the observed drift for subsequent validations, effectively learning per-token offsets and improving user reliability without compromising security.

Real-World Benefits of Drift Compensation

These mechanisms ensure that users of hardware tokens, which may have accumulated significant drift over months, can still authenticate successfully. The combination of a validation window and per-token drift tracking allows Microsoft Entra ID to maintain usability while staying aligned with RFC 6238 recommendations.

Limitations of TOTP and Time Drift Strategies

Despite compensation mechanisms like overlapping validation windows or learned drift adjustment, classic TOTP remains fundamentally vulnerable to certain attack classes — particularly phishing. An attacker who can trick a user into entering a valid TOTP code can immediately reuse it (within the short code validity window). Also, TOTP codes do not provide cryptographic evidence of the authenticating domain or channel, making them susceptible to real-time phishing sites that mirror legitimate login pages.

Stronger Alternatives: FIDO2 and PIV

For scenarios where phishing resistance is required, modern standards like FIDO2 (WebAuthn) or PIV (Personal Identity Verification) smart cards are strongly recommended. In addition to not relying on time, these methods leverage asymmetric cryptography and cryptographically bind authentication to the intended origin, making it infeasible for a malicious site to harvest credentials and reuse them elsewhere.

updated: 15/01/2026 11:04





Classic tokens with Entra ID