When you enable two-factor authentication and scan a QR code with Google Authenticator or Authy, you're setting up an algorithm that generates one-time passwords. But did you know there are actually two different standards for how these codes are generated?

They're called TOTP (Time-based One-Time Password) and HOTP (HMAC-based One-Time Password). Understanding the difference helps you choose the right method for your security needs and troubleshoot issues when codes don't work.

What is HOTP?

HOTP stands for HMAC-based One-Time Password. It's defined by the Internet Engineering Task Force (IETF) in RFC 4226, published in 2005. HOTP was the first widely adopted standard for generating one-time passwords.

HOTP generates codes using two inputs:

The process works like this: when you request a code, the system calculates an HMAC-SHA1 hash of the secret key combined with the current counter value, then truncates it to a 6-digit number. After you use the code, the counter increments on both your device and the server.

Key characteristic of HOTP: Codes are valid indefinitely until used โ€” there's no expiry timer. The code only becomes invalid after it's successfully used or the counter gets out of sync.

What is TOTP?

TOTP stands for Time-based One-Time Password. It's defined in RFC 6238, published in 2011, and extends the HOTP algorithm by replacing the counter with the current time.

TOTP generates codes using:

Instead of a counter, TOTP uses time. The current time is divided by 30 (the time step), and the resulting number is used as the counter input. This means every 30 seconds, the "counter" changes automatically, generating a new code.

Apps like Google Authenticator, Authy, and Microsoft Authenticator all use TOTP. It's also the standard our free 2FA tool uses.

Side-by-Side Comparison

FeatureTOTPHOTP
Full NameTime-based One-Time PasswordHMAC-based One-Time Password
RFC StandardRFC 6238 (2011)RFC 4226 (2005)
Code Generation FactorCurrent time (30-second windows)Incrementing counter
Code Validity30 seconds (typically)Until used or counter drifts
Clock Sync RequiredYes โ€” device time must be accurateNo
Common Attack RiskVery low โ€” short windowCounter drift can cause lockout
Typical UsageGoogle Authenticator, Authy, web appsHardware tokens, some legacy systems
Works Offline?YesYes

Which is More Secure?

Both TOTP and HOTP provide strong security, but they have different risk profiles:

TOTP Security

TOTP is generally considered more secure for software-based 2FA because codes expire quickly. Even if an attacker intercepts a TOTP code (for example, through a phishing site), they have at most 30 seconds to use it. In practice, the server typically allows a slightly wider window (ยฑ1 step, or 90 seconds) to account for clock drift, but the window is still very narrow.

HOTP Security

HOTP codes remain valid indefinitely until used. This means that if an attacker captures an HOTP code before you use it, they could potentially use it at any time in the future. However, the attack requires capturing the specific code before the legitimate user uses it โ€” still a high bar.

HOTP also has a counter synchronization challenge: if codes are generated but not used (for example, if you close the app without submitting), the client counter advances but the server counter doesn't. Most systems handle this with a "lookahead window" that accepts the next N codes, but this slightly reduces the uniqueness guarantee.

Why is TOTP the Standard Today?

TOTP has become the dominant standard for app-based 2FA for several reasons:

When is HOTP Still Used?

HOTP remains useful in specific scenarios:

Bottom line: For everyday use with apps like Google Authenticator or our web-based 2FA tool, you'll be using TOTP. It's the right choice for modern software-based two-factor authentication.

๐Ÿ” Generate TOTP Codes for Free

Our free online 2FA tool uses the TOTP algorithm โ€” the same standard as Google Authenticator.

Open 2FA Generator โ†’

Related Articles