Reduce to digits and keep leading zeros
03A short code is a decimal string, not the whole digest. Reduce the 31-bit integer modulo 10 raised to the agreed digit count, then pad on the left with zeros to that width.
At Unix time 1111111109 the remainder is7081804, but the eight-digit string is07081804. The leftmost zero is part of the code.
Source for this drawing: RFC 6238 · Read RFC source: Appendix B ↗
New to this? Start hereA quick picture + helpful background
A message needs an address.
Think of a packet as a small addressed envelope. Devices pass it onward; transport protocols decide what delivery promises an application gets.
Helpful first, if these ideas are unfamiliar
These pictures are analogies to help you learn. The linked RFC explains the actual rules.
Terms in this drawing
- Modulo
- The remainder after integer division.
- Zero padding
- Adding leading zeros so the decimal string has exactly the agreed number of digits.
Related RFCs and changes
“Updates” changes part of an earlier RFC. “Obsoletes” replaces it. This list shows selected related documents.
TOTP reuses HOTP digit reduction. The Appendix B test vectors use eight digits; this does not make eight digits a universal requirement for every deployment.
- TOTP reuses HOTP digit reduction. The Appendix B test vectors use eight digits; this does not make eight digits a universal requirement for every deployment.
- 1094287082 mod 100000000 = 94287082: the published eight-digit value at time 59 for HMAC-SHA-1.
- With a separately agreed six-digit setting, the same intermediate value gives 1094287082 mod 1000000 = 287082. This is an illustration, not a six-digit Appendix B vector.
- At time 1111111109, the published eight-digit HMAC-SHA-1 value is 07081804. Dropping the leading zero changes the representation; preserve all eight characters.
- HOTP requires at least six digits (RFC 4226 §5.3). Both sides must agree on output width and hash choice to interoperate. Short-code collisions are possible; a new time step is not a uniqueness guarantee.
A decimal code is not an encryption key, signature, identity certificate or proof of which website requested it. This page is an explanation using public fixtures, not a live authenticator. No real account or secret is needed. RFC 4226 §5.3 describes modulo and digit limits; RFC 6238 Appendix B supplies the exact eight-digit expectations.
Read the RFC section ↗