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
| HOTP | TOTP | |
|---|---|---|
| Standard | RFC 4226 (2005) | RFC 6238 (2011) |
| Changing input | A counter that rises with each code | The current time, in 30-second steps |
| Code lifetime | Until it is used, or a later one is | One step, plus a step of grace on most services |
| What can go wrong | Counters drift apart when codes are generated and not used | Codes are refused when the device clock is off |
| Fixing it | The service looks ahead a few counters, up to a limit, to resynchronise | Turn on automatic date and time |
| Needs a clock | No | Yes |
| Typical use | Hardware tokens, some banks, button-press devices | Authenticator apps on almost every website |
| Works offline | Yes | Yes |
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:
| Counter | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| HOTP code | 755224 | 287082 | 359152 | 969429 | 338314 |
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
- Use TOTP for anything an app on a phone or computer will generate. It expires by itself, needs no state to stay in step, and is what nearly every website offers. If a service shows a QR code for an authenticator app, it is TOTP.
- Use HOTP when the device has no clock or no way to keep one, as with some hardware tokens, or when a code should be tied to an event such as a button press rather than to a moment in time. You rarely get to choose: the issuer decides.
- Choose by what you are given. The QR code carries the type, algorithm, digits and either a period or a counter, and a compliant app follows it.
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
- Clock drift: services usually accept a code from one step before or after the current one, so a phone that is a few seconds off still works. Minutes off, and every code is rejected. The fix is to let the device set its clock automatically. When the clock is already correct and a code is still refused, 2FA code not working covers the causes that survive a correct clock.
- Parameters: the default is SHA-1, six digits and 30 seconds. Some services use SHA-256 or SHA-512, seven or eight digits, or a longer period. The QR carries these choices; a compliant app follows them.
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
- Reads every parameter from the
otpauth://link: algorithm (SHA-1, SHA-256, SHA-512), six to eight digits, custom periods, and HOTP counters. - Generates codes on the device and shows the remaining seconds for TOTP entries.
- Stores the secrets encrypted with AES-256-GCM; see how KeyNesta encrypts your 2FA codes.
- Imports the same data from Google Authenticator, Aegis and 2FAS, JSON and CSV.
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