Put your phone in flight mode and open an authenticator app. It still shows a fresh 6-digit code every half minute, and if you type it on your laptop, the login works. The phone never talked to the server. An interviewer might ask exactly that: "So how does the server know the code is right?"
The wrong answer
Most people guess that the server sent the code, or that it came by SMS. Neither is possible: there is no network. The code isn't sent from anywhere.
The secret you scanned once
When you first set up the app, you scanned a QR code. Inside it was a random secret made by the server (an otpauth:// link with the secret in base32). Your phone saved it, the server kept its own copy, and it is never sent again.
The same recipe on both sides
To make a code, the phone counts how many 30-second steps have passed since 1 January 1970, then runs that step number through HMAC, a hash keyed with the secret, and cuts the result down to 6 digits. That is TOTP, defined in RFC 6238 on top of RFC 4226's HOTP. The server does exactly the same with its copy of the secret and its own clock, and compares. Same secret, same step, same code, so no message is needed.
Think of an army sentry asking "password?", but with a twist: both the sentry and the soldier were given one secret rule at posting, and both wear a watch. Every half minute, each can work out the same password without radioing anyone.
Why it holds up
- No way back. You can't work back from a code to the secret, because the hash is keyed and one-way.
- Accept once. The server accepts each code only once and blocks repeated wrong guesses; 6 digits is only a million values.
- Drift. Phone clocks drift a little, so the server also checks the neighbouring time step. RFC 6238 recommends allowing at most one step for network delay.
One twist worth knowing for interviews: passwords are stored as hashes, but the server can't hash a TOTP secret, because it needs the raw key to compute codes. It stores the secret encrypted and access-controlled instead.
What it doesn't protect against
If the secret leaks, anyone can generate your codes. And because you type the code yourself, a fake login page can pass it to the real site while it's still valid. NIST SP 800-63B-4 says plainly: "OTP authentication is not phishing-resistant." In 2023 an attacker phoned a Retool employee, who read out a code during the call; the attacker used it to add their own device. Passkeys (WebAuthn) fix this by binding the login to the real site's name. SMS OTP is a different, weaker method: it travels over the phone network and can be stolen with a SIM swap.
The answer to give
The code isn't sent. Both sides make it.
In the interview: "At setup the QR gives a shared secret. Then the phone and the server each compute the same 6 digits from an HMAC of the secret and the time step, allowing a little clock drift. The server can't hash that secret, so it stores it encrypted, and for phishing, passkeys are better."
Sources: RFC 6238 (TOTP); RFC 4226 (HOTP); NIST SP 800-63B-4; Google Authenticator Key URI format; Retool's incident post (Sept 2023); FBI IC3 PSA on SIM swapping (2022).