OTP & SMS Security

What is HOTP? Counter-Based OTP Explained

HOTP — HMAC-based One-Time Password — explained. The RFC 4226 algorithm, how it differs from TOTP, hardware-token use cases, and modern alternatives.

23 April 20267 min read

StartMessaging Team

Engineering

HOTP is the older, less famous cousin of TOTP. It is the original HMAC-based OTP scheme defined in RFC 4226 and is the algorithm that powered the early generation of hardware authentication tokens — the small key-fobs with a button and an LCD that you might have used to log into a corporate VPN in 2010.

This guide covers what HOTP is, how the algorithm works, when you would still pick it over TOTP today (rarely), and the modern alternatives most teams should reach for.

HOTP — Definition

HOTP — HMAC-based One-Time Password — derives a short numeric code by hashing a shared secret with a monotonically increasing counter. It was published as RFC 4226 in 2005 and inspired TOTP three years later.

Each press of the button on a HOTP token (or each call from a HOTP software client) increments the counter and emits a new code. The code does not change with time — it changes with use. A code printed on a scratch card and left in a drawer for a year is still valid; a code from yesterday’s login is not, because both client and server have moved on.

How HOTP Works

// Inputs: secret K, counter C
HMAC = HMAC-SHA1(K, C)            // 20 bytes
offset = HMAC[19] & 0x0F           // last nibble
truncated = (HMAC[offset]   & 0x7F) << 24
          | (HMAC[offset+1] & 0xFF) << 16
          | (HMAC[offset+2] & 0xFF) << 8
          | (HMAC[offset+3] & 0xFF)
code = truncated % 10^d           // d = 6, usually

On each verification, the server tries the expected counter value plus a small look-ahead window (commonly 10) to forgive accidental increments where the user pressed the button but never typed the code. After a successful verification, the server’s counter advances past the last accepted value to prevent replay.

HOTP vs TOTP

HOTP (RFC 4226)TOTP (RFC 6238)
Counter sourcePer-use counterCurrent 30-second window
Re-use preventionServer tracks last counterServer tracks last accepted window
Code rotationOn user actionEvery 30s automatically
Out-of-sync riskYes — needs look-aheadYes — needs ±1 window for clock drift
Modern adoptionLegacy hardware tokensAuthenticator apps (default)

For a deeper TOTP write-up see our TOTP explainer.

Where HOTP is Still Used

  • Hardware tokens. Many YubiKey and Feitian models have a HOTP button mode for legacy compatibility.
  • Air-gapped environments. Where you cannot rely on a synchronised clock, HOTP avoids the drift problem.
  • Printed scratch-card OTPs. A pre-generated list of HOTP codes printed in a passbook, used in some banking products.

Pitfalls

  • Drift. Counter desynchronisation is the #1 source of support tickets. Tune the look-ahead window carefully — too small and you lock users out, too large and you increase brute-force surface.
  • Replay. Always advance the server counter past the last accepted value.
  • Hardware loss. A HOTP key is single-purpose; users will lose them. Plan recovery flows up front.

Modern Alternatives

Most products that would historically have picked HOTP now reach for one of:

  • TOTP — same crypto, no counter sync issues.
  • SMS OTP — universal handset support, instant delivery via a managed OTP API.
  • FIDO2 / passkeys — phishing-resistant, no shared secret to leak.

FAQ

For most Indian-market apps, the practical answer is SMS OTP via StartMessaging for primary auth and TOTP as an opt-in upgrade. HOTP rarely earns its slot on the menu in 2026.

Ready to Send OTPs?

Integrate StartMessaging in 5 minutes. No DLT registration required.