Two-Factor Authentication: How It Works and Why You Need It

A stolen password used to mean a compromised account. Two-factor authentication (2FA) breaks that assumption: even if an attacker knows your exact password, they cannot log in without a second proof of identity. Google's internal data found that enabling 2FA blocks 100% of automated bot attacks. Here's how each 2FA method works and how to choose the right one.

What Is Two-Factor Authentication?

Authentication factors fall into three categories: something you know (a password), something you have (a phone, a hardware key), and something you are (a fingerprint, a face). A password alone is single-factor — one category. Two-factor authentication requires proof from two different categories.

The term 2FA is often used interchangeably with MFA (multi-factor authentication), though MFA can technically mean three or more factors. In practice, two factors — usually a password plus a time-based code — is the standard most consumers and businesses aim for.

The security benefit is clear: credential databases are breached regularly. When attackers get your email and password from a leaked database, they try those credentials on every other service you use — a technique called credential stuffing. With 2FA enabled, a stolen password is worthless without also controlling your second factor.

TOTP: How Authenticator Apps Work

The most widely used and recommended form of 2FA for consumer accounts is TOTP — Time-based One-Time Password — defined in RFC 6238.

Here's the mechanism: when you set up 2FA on a service, it gives you a secret key (usually as a QR code). Your authenticator app stores this key. Every 30 seconds, the app uses that secret key combined with the current Unix timestamp to compute a 6-digit code using the HMAC-SHA1 algorithm. The server does the same calculation. If the codes match, you're authenticated.

TOTP code = HMAC-SHA1(secret key, current time slot) — truncated to 6 digits. Valid for 30 seconds.

This is elegant because the code changes every 30 seconds, cannot be predicted without the secret key, and requires no internet connection to generate on your device. Popular TOTP apps include Google Authenticator, Authy, and the open-source Aegis (Android).

When choosing an authenticator app, prefer one that offers encrypted cloud backup (Authy, 1Password) so you're not locked out if you lose your phone, or one that lets you export your secrets locally (Aegis). Google Authenticator added cloud backup in 2023, but it encrypts backups only with your Google account — a reasonable option for most users.

security

Try TOTP Generator

GlintKit's TOTP generator lets you generate time-based one-time passwords from any secret key, right in your browser — great for testing 2FA setups.

arrow_forward Try TOTP Generator

SMS 2FA: Better Than Nothing, But Weak

SMS-based 2FA sends a one-time code to your phone number via text message. It's the most common form of 2FA because it requires no app installation and works on any phone. But it has significant weaknesses:

SIM Swapping

An attacker can call your mobile carrier, impersonate you using personal information obtained from data brokers or social engineering, and convince them to transfer your phone number to a SIM card the attacker controls. From that point on, all SMS messages — including 2FA codes — go to the attacker. High-profile victims have included Twitter CEO Jack Dorsey and cryptocurrency investors who lost millions.

SS7 Vulnerabilities

The telephony protocol underlying SMS (Signaling System No. 7) has known security vulnerabilities that allow sophisticated attackers — including state actors — to intercept text messages in transit.

Phishing

A real-time phishing attack can trick you into entering your SMS code on a fake login page, which the attacker immediately relays to the real site. Unlike hardware keys (see below), SMS codes provide no phishing protection.

The verdict on SMS 2FA: use it over nothing, but upgrade to an authenticator app or hardware key for any account worth protecting.

Hardware Keys: The Gold Standard

Hardware security keys (YubiKey, Google Titan Key) implement the FIDO2/WebAuthn standard and are the most phishing-resistant form of 2FA available to consumers.

When you register a hardware key with a service, the key generates a unique cryptographic key pair for that specific website. To authenticate, you plug in the key (USB) or tap it (NFC) and it performs a cryptographic challenge-response. The critical security property: the key verifies the website's domain as part of the authentication. If you're on a phishing site that looks identical to your bank, the key refuses to authenticate because the domain doesn't match the domain it registered with. No code to steal, no way to relay credentials.

Hardware keys are recommended for anyone who manages sensitive systems, cryptocurrency, or is at elevated risk of targeted attack. They cost $25–$60 and are supported by Google, GitHub, Dropbox, Facebook, Microsoft, and most major services.

How to Set Up 2FA on Major Services

The process is similar across most services:

  1. Go to your account's security settings (usually under Settings > Security > Two-Factor Authentication)
  2. Choose your preferred method — authenticator app is recommended over SMS
  3. If using an authenticator app: scan the QR code with your app. The app will immediately start generating codes.
  4. Enter the current 6-digit code from your app to confirm setup
  5. Save your backup codes in a safe place

Priority accounts to enable 2FA on first: your primary email account (everything resets flow through email), your password manager, work accounts, banking and financial services, and any account with payment information saved.

Backup Codes: Don't Skip This Step

When you set up 2FA, most services give you a set of single-use backup codes — typically 8–16 digit codes you can use if you lose access to your authenticator app. These are critically important.

If your phone is lost, stolen, or broken without a backup of your authenticator app secrets, you may be permanently locked out of accounts without backup codes. Store them somewhere secure and offline: printed in a fireproof safe, in a password manager's secure notes, or in an encrypted file. Do not store them in your regular notes app unencrypted.

Phishing-Resistant 2FA: The Future

The industry is moving toward passkeys (FIDO2/WebAuthn without a hardware device), which store cryptographic keys in your device's secure hardware — your phone's secure enclave or laptop's TPM chip. Passkeys are phishing-resistant by design, do not require a hardware key purchase, and are supported by major platforms including Apple, Google, and Microsoft. They may eventually replace passwords entirely, but for now they coexist with traditional authentication methods.

The Bottom Line

Two-factor authentication is the single highest-impact security improvement most people can make today. A stolen password alone is no longer enough to access a 2FA-protected account. Use a TOTP authenticator app rather than SMS where possible, save your backup codes, and prioritize enabling 2FA on your most critical accounts first: email, password manager, and financial accounts. If you handle particularly sensitive data or are at elevated risk of targeted attack, invest in a hardware security key.