Blog

Blog

Articles about two-factor authentication, TOTP security, and best practices for protecting your online accounts.

How TOTP Code Generation Works

Visual flow of the RFC 6238 time-based one-time password algorithm

Step 1Base32

Secret Key

Shared Secret

JBSWY3DPEH...
Step 2Unix

Unix Time

seconds since 1970-01-01

1741531200
Step 3T = t / 30

Time Counter

30s time step

58051040
Step 4HMAC-SHA

HMAC-SHA Hash

HMAC(secret, counter)

160-bit digest
Step 5Expires in 30s

Dynamic Truncation

482901

& 6-digit output

RFC 6238TOTP = HOTP(SecretKey, ⌊(CurrentTime − T0) / TimeStep⌋)
T0 = 0 (Unix Epoch)•TimeStep = 30s

The TOTP algorithm combines your shared secret key with the current Unix timestamp divided by a time step (default 30 seconds). This value is hashed using HMAC-SHA-1, SHA-256, or SHA-512. The resulting hash is then dynamically truncated to produce a 6 or 8-digit code. Because the time counter changes every 30 seconds, a new code is generated automatically, making intercepted codes useless after expiration.

Algorithm Comparison

Comparison of hash functions used in TOTP implementations

AlgorithmHash FunctionOutput BitsSecurity LevelSpeedBest For
SHA-1HMAC-SHA-1160StandardFastestConsumer Apps
SHA-256HMAC-SHA-256256EnhancedFastBusiness/Enterprise
SHA-512HMAC-SHA-512512MaximumModerateHigh-Security

Step-by-Step Setup Guide

Follow these steps to set up and secure your accounts with authenticator apps

StepActionDetails
1Choose an AuthenticatorDownload Google Authenticator, Authy, or Microsoft Authenticator from your app store.
2Enable 2FA on Service[Launch Generator ↑]Go to your account's security settings and select 'Enable Two-Factor Authentication'.
3Scan QR CodeUse your authenticator app to scan the QR code displayed on screen.
4Save Backup Codes[Save in Vault ↑]Download or write down the backup codes provided by the service.
5Verify SetupEnter the 6-digit code from your app to confirm setup is working correctly.

Stay Updated

Get the latest security tips and TOTP best practices delivered to your inbox.