TOTP in one sentence
A TOTP code is a short number calculated from two ingredients: a secret key that only you and the website know, and the current time. Because both sides have the same key and the same clock, they calculate the same code without ever sending it over the internet.
TOTP is defined in an open standard called RFC 6238. It builds on an older standard, HOTP (RFC 4226), which uses a counter instead of the time. Because the standard is open, any TOTP code generator can create codes for any website that supports authenticator apps.
How a TOTP code is generated
Every authenticator follows the same recipe:
- Take the secret key. It is usually written in Base32, a format that uses the letters A–Z and the digits 2–7, for example
JBSW Y3DP EHPK 3PXP.
- Count the time steps. The current Unix time (seconds since 1 January 1970) is divided by the time step, normally 30 seconds. Every 30 seconds this number goes up by one.
- Mix them with HMAC. The key and the time-step number are combined with a hash function, by default HMAC-SHA1. Some services use SHA-256 or SHA-512.
- Shorten the result. The long hash is cut down to a short number, usually 6 digits (sometimes 8).
The website runs the same calculation when you log in. If your code matches, you are in. Many websites also accept the code from one step before or after, to allow for small clock differences.
Why do TOTP codes change every 30 seconds?
A short lifetime makes a stolen code almost worthless. Even if someone sees your screen or intercepts a code, it expires within seconds. Thirty seconds is a balance: long enough to read and type the code, short enough to limit misuse.
This is also why the clock on your device matters. If your device time is wrong by a minute or more, your authenticator calculates codes for the wrong moment, and the website rejects them. Our guide Why is my 2FA code not working? shows how to fix that.
What is inside a TOTP QR code?
The QR code a website shows during 2FA setup is just a text link in this format:
otpauth://totp/Example:you@example.com?secret=JBSWY3DPEHPK3PXP&issuer=Example
It contains the secret key, the account name, the issuer (the website), and sometimes extra settings such as digits, period or algorithm. Our TOTP code generator reads both plain secret keys and full otpauth:// links, including 6 to 10 digits, custom periods and SHA-1, SHA-256 or SHA-512.
How to use a TOTP code generator online
- Find your secret key or QR code in the website's 2FA settings (see where to find your 2FA secret key).
- Open the TOTP generator and paste the key, scan the QR code with your camera, or upload a screenshot of it.
- Read the 6-digit TOTP code and the countdown. The next code is shown too, so you can wait for a fresh one if time is short.
- Type the code on the website before it expires.
Everything happens in your browser. The secret key is not uploaded anywhere, and the page keeps working even if you go offline after it has loaded.
Frequently asked questions
What does TOTP stand for?
TOTP stands for time-based one-time password. It is a short code calculated from a secret key and the current time, defined in the open standard RFC 6238.
What is the difference between TOTP and OTP?
OTP means any one-time password. TOTP is one specific kind of OTP that changes with time, usually every 30 seconds. Codes sent by SMS are also OTPs, but they are not TOTP codes.
Is a TOTP code always 6 digits?
Most services use 6 digits, but the standard also allows 8 digits and other lengths. If a website uses a different length, it is included in the setup QR code.
Do TOTP codes need an internet connection?
No. The code is calculated from the secret key and your device clock, so an authenticator can create TOTP codes offline. Only the login itself needs the internet.