How a 2FA code is made
Time-based one-time passwords are defined in RFC 6238, published by the IETF in May 2011, and build on the counter-based HOTP method in RFC 4226 from December 2005. The service and your app share a secret key. Every 30 seconds the current Unix time is divided by the period to give a step number; the step is signed with HMAC using the secret, four bytes are picked out of the result by a rule called dynamic truncation, and the number is cut to six or eight digits. Because both sides know the time and the secret, they arrive at the same code without talking to each other. Nothing about the code reveals the secret, and a code is useless once its step has passed.
Secret keys and otpauth links
When you turn on two-factor login, the service shows a QR code. Inside it is a link that starts with otpauth://totp/, followed by a label with the service and account name and a secret parameter written in Base32, the alphabet A to Z plus 2 to 7 defined in RFC 4648. Optional parameters set the algorithm, the number of digits and the period; when they are missing, SHA-1, six digits and 30 seconds are assumed. The "can't scan?" option on most setup screens shows the same Base32 secret as text. Paste either form here. Counter-based HOTP links are not supported, because each code there depends on a counter only your app knows.
Keep the secret private
The secret is the second factor itself: anyone who has it can make your codes forever, until you turn 2FA off and on again. Use this page for testing, for checking a backup, or for learning, on a device you trust, and do not paste the secrets of important accounts into any website you do not control. Here the code is computed with the Web Crypto API in your browser and nothing is sent or logged; the secret is not stored unless you tick Remember, which keeps it in this browser's local storage only until you untick it. The random secret button makes a new 160-bit key, the length RFC 4226 recommends, which you can scan into an app to try a setup end to end.
When the code is rejected
The most common cause is the clock. The code depends on the time, so a phone or computer whose clock is a minute off produces codes the service does not accept; turn on automatic time in your device settings. RFC 6238 lets services accept a code from a step or two around the current one to allow for drift, which is why the previous and next codes are shown. Other causes are a mistyped secret (the letter O and the digit 0 are not both valid Base32), a service that uses SHA-256 or eight digits, or a 60-second period. Check what the setup screen or otpauth link says and match it here.
Sources and related tools
We read the specifications on 23 October 2026 and checked this generator against every test value they publish: the ten HOTP codes in Appendix D of RFC 4226 and the eighteen SHA-1, SHA-256 and SHA-512 codes in Appendix B of RFC 6238. To protect the accounts behind your codes, start with a strong unique password from our password generator, check it with the password breach checker, and keep backup codes somewhere safe.
- RFC 6238: TOTP: Time-Based One-Time Password Algorithm (IETF, May 2011), opened 23 Oct 2026
- RFC 4226: HOTP: An HMAC-Based One-Time Password Algorithm (IETF, December 2005), opened 23 Oct 2026
- RFC 4648: Base16, Base32, and Base64 Data Encodings (IETF), opened 23 Oct 2026
- Strong password generator
- Password breach checker
- Encrypt and decrypt text