HOTP vs TOTP: the difference, explained

Published 19 September 2026. Updated 16 November 2026. About 8 minutes.

The short answer

HOTP (HMAC-based one-time password, RFC 4226) makes a code from a secret and a counter that goes up each time a code is used. TOTP (time-based one-time password, RFC 6238) is HOTP with the counter replaced by the current time, so a TOTP code changes by itself every 30 seconds. Websites almost always use TOTP; HOTP lives on in hardware tokens and a few banks.

What is HOTP?

HOTP is the original one-time-password standard, published in 2005 as RFC 4226. The service and your token share a secret and a counter that both start at the same number. To make a code, each side runs the secret and the counter through HMAC-SHA-1, then truncates the result to a short number, usually six digits. After a code is used, both counters move up by one, so the next code is different.

Nothing in HOTP says a code ever expires. A code stays valid until the service sees it used, or sees a later one, which is the property that separates it most sharply from TOTP.

What is TOTP?

TOTP, published in 2011 as RFC 6238, swaps the counter for time. It divides the Unix clock into steps of 30 seconds by default, and uses the step number as the HOTP counter. Because your phone and the service both know the time, neither needs to remember how many codes have been used, and a code expires on its own when its step ends. This is the six-digit code that counts down in every authenticator app, KeyNesta included.

HOTP vs TOTP at a glance

HOTPTOTP
StandardRFC 4226 (2005)RFC 6238 (2011)
Changing inputA counter that rises with each codeThe current time, in 30-second steps
Code lifetimeUntil it is used, or a later one isOne step, plus a step of grace on most services
What can go wrongCounters drift apart when codes are generated and not usedCodes are refused when the device clock is off
Fixing itThe service looks ahead a few counters, up to a limit, to resynchroniseTurn on automatic date and time
Needs a clockNoYes
Typical useHardware tokens, some banks, button-press devicesAuthenticator apps on almost every website
Works offlineYesYes

A worked example with real codes

RFC 4226 publishes test values you can check any implementation against. The shared secret is the ASCII string 12345678901234567890, which an authenticator app stores in base32 as GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ. With HMAC-SHA-1 and six digits, the HOTP codes for counters 0 to 4 are:

Counter01234
HOTP code755224287082359152969429338314

Now TOTP. RFC 6238 uses the same secret. At Unix time 59 seconds the 30-second step number is 1, so the TOTP code is the HOTP code for counter 1: 287082 with six digits (the RFC lists its eight-digit form, 94287082). At Unix time 1111111109 the step is 37037036 and the eight-digit code is 07081804. Same secret, same algorithm: the only thing TOTP changed is where the counter comes from. The test secret is public, so it belongs on no real account; test your authenticator lets you do the same comparison live with a different one.

When to use each

Is TOTP more secure than HOTP?

Neither is stronger in its cryptography: both rest on the same HMAC over the same kind of shared secret. TOTP gives a shorter window for a stolen code to be useful, because it expires within about a minute, while an unused HOTP code can stay valid for a long time. Both can be phished, since either can be typed into a lookalike site, which is why a security key or a passkey beats both against phishing.

The shared secret

When you enable 2FA on a service, it shows a QR code. That QR encodes an otpauth:// link containing a random secret (written in base32), plus the issuer, your account name, and a few parameters: the hash algorithm, the number of digits, and either a time period or a counter. Your app stores the secret; the service stores the same secret. From then on, nothing is transmitted when you generate a code. Both sides compute it independently.

That is why the QR is sensitive: anyone who scans it can generate your codes forever. It is also why KeyNesta decodes imports on your device and never uploads them.

And it is why two devices holding the same secret show identical codes, with no pairing step to look for and no device list on the account: an authenticator app on two devices covers the three routes to a second device and what each one costs.

Clock drift and parameters in TOTP

You can watch that agreement happen: test your authenticator computes the code for a published test secret in your browser, so whatever app you scan it with should show the same six digits at the same moment.

Counter drift in HOTP

If you generate HOTP codes without using them, your counter runs ahead of the service's. The service looks a few counters ahead to resynchronise, but only up to a limit; past it, the codes are refused until the service is resynchronised or the token is re-enrolled. That fragility is the main reason most websites chose TOTP.

Why codes work offline

Generating a code needs only the secret and either the clock or the counter, both of which are on your device. No network, no account, no server. This is also why an authenticator app should never need internet access to show a code; if one does, something other than the standard is going on.

It is also the difference from SMS codes, which are sent to you over the phone network at login time and can be redirected by a SIM swap. Authenticator app vs SMS covers what that changes, and what neither kind of code protects against.

What KeyNesta does with all this

Frequently asked questions

What is HOTP?

HOTP is the HMAC-based one-time password standard, RFC 4226. It makes a code from a shared secret and a counter that rises each time a code is used, so every code differs from the last. It is used mainly in hardware tokens and some banks.

What is the difference between HOTP and TOTP?

HOTP builds the code from a counter that rises with each use. TOTP builds it from the current time in 30-second steps, so it changes by itself and expires within about a minute. Everything else, the secret, the HMAC and the truncation, is the same.

Is TOTP more secure than HOTP?

Neither is inherently stronger. Both derive the code from the same HMAC construction over a shared secret. TOTP is more common because time is easier to keep in sync than a counter, and a code expires on its own after the period ends.

Why does my code differ from what the service expects?

Almost always a clock problem: the device time is off by more than the service tolerates. Turn on automatic time setting and try again. If only one service fails, its QR may specify a different algorithm or digit count that the app did not honour; KeyNesta reads those parameters from the QR.

Can I change the period or number of digits?

Only if the service issued them that way. The parameters in the QR must match what the service computes. KeyNesta supports six to eight digits, SHA-1, SHA-256 and SHA-512, and custom periods, but it uses whatever the QR specifies.

What exactly is in the QR code?

An otpauth:// link with the secret, issuer, account name, and optional algorithm, digits, period or counter. It contains everything needed to generate your codes, so treat it like a password and delete screenshots once the account is set up.

Try KeyNesta free. The web app needs no sign-up.

Open the web app All platforms