How TOTP works
TOTP combines a shared secret with the current time. The clock is divided into 30-second steps; the step number is fed through HMAC-SHA1 with the secret and truncated to a 6-digit code. Because both the server and your app know the secret and agree on the time, they compute the same code independently — nothing is ever sent over the network to generate it.