Skip to content

The TOTP Standard Explained: How Time-Based One-Time Passwords Actually Work

Every time you open an authenticator app and see a six-digit code, a fascinating piece of cryptographic engineering is happening in the background. Understanding how TOTP works isn't just technically interesting — it explains why it's so secure, where its limits are, and how to use it correctly in an enterprise environment.

The TOTP Standard Explained: How Time-Based One-Time Passwords Actually Work

Open your authenticator app right now. There's a six-digit code. In about 30 seconds, it will change to a completely different six-digit code. And critically — that new code was mathematically determined before your phone even knew it was going to be generated.

This is TOTP: Time-Based One-Time Password. It's the mechanism behind virtually every authenticator app in use today — Google Authenticator, Microsoft Authenticator, Authy, and OWD Authenticator. It's standardized in RFC 6238, widely audited, and when implemented correctly, represents one of the most practical and effective second-factor mechanisms available.

Understanding how it works isn't just academic. It explains exactly why it's so hard to attack, where the real security boundaries are, and how enterprise organizations should approach managing TOTP at scale.

The Foundation: HMAC-Based OTP

Before TOTP, there was HOTP — HMAC-Based One-Time Password (RFC 4226). HOTP generates a code based on two inputs:

  1. A shared secret — a random string of bytes established when you scan a QR code
  2. A counter — an integer that increments with each code used

The algorithm applies HMAC-SHA1 to the combination of secret and counter, then truncates the result to produce a 6–8 digit code. Both the server and your authenticator app start with the same secret and counter, apply the same function, and arrive at the same code — without ever transmitting the secret.

HOTP works, but has a practical problem: the counter has to stay synchronized between your device and the server. If you generate codes without using them, the counter drifts, and authentication fails.

How TOTP Solves the Synchronization Problem

TOTP replaces the counter with time. Specifically, the current Unix timestamp divided by 30 — giving a value that changes every 30 seconds and is the same for both your device and the server, as long as clocks are synchronized (which they almost always are on internet-connected devices).

The algorithm:

T = floor(current_unix_time / 30)
code = HOTP(shared_secret, T)

Both your authenticator app and the server know the shared secret (established during setup). Both know the current time. Both apply the same deterministic function. Both arrive at the same 6-digit code — without any communication between them after the initial secret exchange.

This is the elegant core of TOTP. The code is correct because both parties share a secret and can independently compute the same time-based function. No state needs to be transmitted. No counter needs to be synchronized.

The Security Properties of TOTP

Short Window, Short Exposure

Codes are valid for 30 seconds. In practice, most implementations accept codes from adjacent time windows (±1 window, so up to 90 seconds) to account for clock drift. But even at 90 seconds, an intercepted code has a very small window of usability.

Contrast this with a password: if your password is compromised, it's valid indefinitely until changed. An intercepted TOTP code becomes worthless in under two minutes.

The Secret Never Travels After Setup

Once the shared secret is established (typically by scanning a QR code that encodes the secret), it never needs to be transmitted again. Your authenticator app stores it locally. The server stores it. Each independently computes codes from that shared secret.

An attacker monitoring your network traffic after setup can capture TOTP codes — but they expire before the attacker can realistically use them for most attack scenarios. The secret itself is never on the wire.

No Server Interaction Required

Your authenticator app generates codes entirely offline. There's no network request to a central server to retrieve or validate a code. The computation happens locally, on your device, using just the stored secret and the current time.

This means TOTP works on airplane mode. It works when the authenticator app's servers are down. It works in countries where certain internet services are blocked. The authentication is peer-to-peer in a cryptographic sense — two parties that share a secret, computing the same function independently.

Where TOTP Has Limits

Honesty about security requires acknowledging the limits.

Phishing Is Still Possible

TOTP doesn't protect against real-time phishing. An attacker who builds a convincing fake login page can intercept both your password and your TOTP code, then use them to log into the real service within the valid time window. This is an active attack that requires more sophistication than credential stuffing — but it happens.

For the highest-security accounts, hardware security keys using FIDO2/WebAuthn are phishing-resistant in a way TOTP is not — the authentication is cryptographically bound to the actual domain, so fake sites can't capture useful credentials.

For most enterprise use cases, however, TOTP provides a massive security improvement over passwords alone. The sophistication required for real-time TOTP phishing attacks is orders of magnitude higher than the credential-stuffing attacks that account for the majority of breaches.

Secret Theft Is a Risk

The security of TOTP depends on the security of the shared secret. If an attacker obtains the secret (from a compromised device, a breached authentication database, or insecure initial setup), they can generate valid codes indefinitely.

This is why the security of secret storage matters enormously — both on the server side and on the device/app side. Authenticator apps that store secrets in unencrypted local storage, back them up to unsecured cloud accounts, or expose them through inadequate device security policies represent real risks.

This is one of the core reasons OWD Authenticator was built with an encrypted vault architecture — the shared secrets are protected at rest, each encrypted with its own key, and managed centrally so that organizations retain control over their TOTP secrets even when employees change devices or leave the company.

Consumer Apps Create Organizational Blind Spots

When employees use consumer authenticator apps — Google Authenticator, for instance — the organization has no visibility into or control over those secrets. If an employee leaves, their TOTP access leaves with them. If they lose their phone, recovering access requires IT intervention and often manual secret re-enrollment.

At small scale, this is manageable. At enterprise scale, it's an operational and security liability. Centralized TOTP management — where the organization owns the secrets, controls access, and can provision or deprovision instantly — is the mature approach for any organization beyond early-stage startup.

Managing TOTP at Enterprise Scale

The operational challenges of TOTP at scale come down to a few recurring problems:

Secret distribution during setup. QR codes sent over email or Slack are a security risk. Proper TOTP onboarding requires a secure, verified channel for secret delivery.

Recovery when second factors are lost. An employee loses their phone. How does your IT team verify their identity and restore access securely without creating a social engineering vector? This process needs to be designed and documented before you need it.

Off-boarding. When an employee leaves, their TOTP access to every service they used needs to be revoked. With consumer authenticator apps, this requires re-rolling secrets on every service. With centralized management, it's a single action.

Audit visibility. For compliance purposes, organizations often need to demonstrate that MFA was enforced and audit who authenticated when. Consumer apps provide none of this. Enterprise platforms provide full logs.

OWD Authenticator addresses most of these at the platform level — centralized secret management, team sharing, encrypted vault storage, and admin controls designed for organizations that need to manage TOTP as an enterprise security control rather than a collection of individual employee preferences.

The Standard That Earned Its Place

TOTP has been around since 2011. It's been scrutinized, attacked, and stress-tested extensively. Its security properties are well-understood. Its weaknesses are documented and manageable.

For most organizations, it represents the best balance available between security effectiveness and practical usability — strong enough to stop the vast majority of credential-based attacks, simple enough for every employee to use without training.

Understanding the cryptography behind it isn't just intellectually satisfying. It helps you understand exactly what you're getting, what you're not, and how to build the organizational processes that make TOTP work reliably at scale.

TOTPauthenticatortwo-factor authenticationcryptographyenterprise securityOWD AuthenticatorMFA

All posts

Try a Windows computer free for 7 days

Your first computer is free for 7 days on the Launch plan, and ready in minutes. We ask for a card at the start, and you can cancel before the trial ends.