Get2FA

← All guides

What is TOTP? (and TOTP vs HOTP)

TOTP stands for Time-based One-Time Password. It's the algorithm behind the 6-digit codes in Google Authenticator and almost every authenticator app, defined in RFC 6238.

Updated 2026-11-19

Have your secret key? Get your code nowOpen the 2FA generator

TOTP meaning

A time-based one-time password is a short code calculated from two inputs: a shared secret key and the current time. The server and your app both know the key and the time, so they calculate the same code without talking to each other.

How a TOTP code is generated

  1. Take the current Unix time and divide it by the period (usually 30 seconds). The whole number is the counter.
  2. Calculate HMAC-SHA1 (or SHA-256/SHA-512) of the counter using the secret key.
  3. Pick 4 bytes from the result (“dynamic truncation”) and turn them into a number.
  4. Keep the last 6 (or 8) digits. That's the code.

Because the counter changes every 30 seconds, the code does too. That's why a wrong device clock makes codes fail.

TOTP vs HOTP

TOTPHOTP
Moving factorTime (every 30 s)A counter that goes up on each use
StandardRFC 6238RFC 4226
Code expiresYes, after the periodNo, until the next one is used
Typical useAuthenticator apps, 2FA on websitesHardware tokens with a button

TOTP is really HOTP with the time as the counter, which makes codes short-lived and harder to reuse.

TOTP secret and QR code

The secret is usually a Base32 string (letters A–Z and digits 2–7). Sites share it as a QR code containing an otpauth://totp/…?secret=… link, which can also set the algorithm, digits and period.

Generate a TOTP code

Have your secret key? Get your code nowOpen the 2FA generator

Guides