Real World Maths Busters

The Maths Behind Everyday Life

The story, the formula and a worked example — see exactly where this maths shows up in the world around you.

Back to all stories
Technology 3 min read

Why your authenticator code changes every 30 seconds

A shared secret plus the current time generates a fresh 6-digit code — one of a million.

Authenticator apps show a 6-digit code that refreshes every 30 seconds. Both your app and the server mix a shared secret with the current time, so they compute the same code without ever sending it.

Hash the secret with the time

A time-based one-time password hashes the secret together with the current 30-second time step, then truncates to 6 digits — one of a million values.

code=HASH(secret,⌊t/30⌋) mod 106\text{code} = \text{HASH}(secret, \lfloor t/30 \rfloor) \bmod 10^{6}

TOTP code

Why it expires

The time step changes.

A short-lived secret

  1. 1

    Code space

    106=1,000,00010^{6} = 1{,}000{,}000
  2. 2

    30-second window

    After 30 seconds the time step changes and the old code is useless — even if intercepted.

Answer

A million possible codes, each valid for only 30 seconds, foils reuse.

The formula behind it

TOTP

HASH(s,t) mod 106\text{HASH}(s, t) \bmod 10^{6}

The takeaway

TOTP mixes a shared secret with the clock to make a 6-digit code that both sides can compute but which expires in seconds.

Back to all stories