What Base32 is
Base32 writes binary data as text using 32 characters: the letters A to Z and the digits 2 to 7. Every 5 bits of input become one character. It is defined in RFC 4648, section 6, alongside Base64 and Base16 (hex).
Base32 output is longer than Base64, but it has two properties Base64 lacks. It is case-insensitive, so mzxw6 and MZXW6 decode the same. And it avoids characters people confuse: there is no 0, 1 or 8, which look like O, I and B.
Those properties are why Base32 is the standard way to show one-time password secrets. A secret that someone may have to type from a screen, when a QR code cannot be scanned, needs to survive human reading.
How Base32 encoding works
The encoder reads the input 5 bytes (40 bits) at a time and splits each group into eight 5-bit values. Each value from 0 to 31 picks a character from the alphabet. When the input does not fill the last group, the bits are padded with zeros and the output is padded with = to a multiple of eight characters.
Input: "foo" = 0x66 0x6F 0x6F
Bits: 01100110 01101111 01101111
Groups: 01100 11001 10111 10110 1111(0)
Values: 12 25 23 22 30
Output: M Z X W 6 + "===" padding
Result: MZXW6===| Values | Characters |
|---|---|
| 0 to 25 | A to Z |
| 26 to 31 | 2 to 7 |
| Padding | = |
The RFC 4648 test vectors
| Input | Base32 |
|---|---|
| (empty) | (empty) |
f | MY====== |
fo | MZXQ==== |
foo | MZXW6=== |
foob | MZXW6YQ= |
fooba | MZXW6YTB |
foobar | MZXW6YTBOI====== |
This tool reproduces all of these, both encoding and decoding.
Base32 compared with Base64 and hex
| Encoding | Bits per character | Size of 20 bytes | Case-sensitive | Typical use |
|---|---|---|---|---|
| Hex (Base16) | 4 | 40 characters | No | Hashes, keys in logs |
| Base32 | 5 | 32 characters | No | OTP secrets, human-typed codes |
| Base64 | 6 | 28 characters | Yes | Binary in text formats, PEM |
| Base64url | 6 | 27 characters | Yes | Tokens, URLs, JWT parts |
Base32 sits between hex and Base64: shorter than hex, longer than Base64, and the only one of the three that is both case-insensitive and free of look-alike characters.
Other Base32 alphabets
Several Base32 variants exist, with different alphabets. They are not interchangeable: the same bytes give different text.
- RFC 4648 Base32 (this tool):
A–Z 2–7. Used for OTP secrets and most general purposes. - RFC 4648 base32hex (section 7):
0–9 A–V. Keeps the sort order of the data; used in DNSSEC. - Crockford’s Base32: digits and letters without I, L, O and U, with decoding that maps look-alikes to the right value. Used by some identifier formats.
- z-base-32: an alphabet ordered for easy reading by people.
If a value will not decode here, check which variant produced it.
What this tool does and does not do
- It encodes UTF-8 text or hex bytes to RFC 4648 Base32, with or without
=padding. - It decodes Base32 to text and hex, forgiving lowercase, spaces, dashes and missing padding, since OTP secrets are often shown in grouped lowercase.
- It reports invalid characters by name, and explains that 0, 1 and 8 are not Base32 characters.
- It rejects lengths no valid Base32 can have, which usually means a character was lost in copying.
- It does not handle base32hex, Crockford’s variant or other alphabets.
How to encode and decode
- Choose Encode or Decode. Switching carries the current result across, so you can round-trip.
- To encode, choose text or hex input and paste the data.
- To decode, paste the Base32. Grouped, lowercase text is fine.
- Read the output. When decoding, the text view appears if the bytes are valid UTF-8; the hex view always works.
Base32 and one-time password secrets
An authenticator app’s secret is random bytes, typically 20 of them (160 bits). Shown in Base32 they become 32 characters, which is why setup screens show them in groups of four, in the style of the example JBSW Y3DP EHPK 3PXP.
In Keycloak
When a user sets up OTP in Keycloak, the setup page shows a QR code and, for manual entry, the secret in Base32. The QR code holds an otpauth URI with the same Base32 secret. Use this tool to confirm that a secret someone typed decodes to the expected number of bytes.
Debugging codes that never match
A common implementation bug is to use the Base32 text itself as the HMAC key. The key must be the decoded bytes. Decode the secret here, take the hex, and compare it with the key your code uses.
Typing secrets by hand
People mistype secrets. The usual errors are 0 for O, 1 for I or L, and 8 for B. Since none of 0, 1 or 8 is valid Base32, a decoder can flag the mistake rather than silently producing a wrong key, as this one does.
Common mistakes
- Confusing Base32 with Base64. A value with lowercase and uppercase letters,
+or/is Base64. - Expecting Base32 to hide data. It is an encoding anyone can reverse.
- Mixing alphabets, such as decoding base32hex with a standard decoder.
- Dropping a character when copying a grouped secret. The decoder catches lengths that cannot be valid, but not every lost character.
- Adding padding where an app expects none, or the reverse.
Security notes
Base32 is not encryption. A Base32 OTP secret is exactly as sensitive as the raw bytes: anyone who has it can generate codes. Paste real secrets only where you must, and prefer test values.
This tool runs entirely in your browser and sends nothing.
Lengths and padding
Base32 works in groups of 5 bytes, which become 8 characters. A last group that is shorter produces fewer characters, and padding fills the rest. Only five remainders are possible, which is why some lengths can never be valid.
| Bytes in the last group | Characters | Padding | Unpadded length mod 8 |
|---|---|---|---|
| 5 | 8 | none | 0 |
| 4 | 7 | = | 7 |
| 3 | 5 | === | 5 |
| 2 | 4 | ==== | 4 |
| 1 | 2 | ====== | 2 |
An unpadded Base32 string whose length leaves 1, 3 or 6 when divided by 8 cannot be valid. If you see that error here, a character was lost or added when the secret was copied.
Bits left over in the last character must be zero in a canonical encoding. Lenient decoders, including this one, ignore them rather than reject the input.
Base32 in code
Many languages include an RFC 4648 Base32 codec in their standard library; JavaScript does not, so browser and Node.js code uses a small function or a library.
# Python: encode and decode
import base64
base64.b32encode(b"foobar") # b'MZXW6YTBOI======'
base64.b32decode("MZXW6YTBOI======") # b'foobar'
# Decoding a lowercase, unpadded OTP secret in Python
secret = "mzxw 6ytb oi".replace(" ", "").upper()
base64.b32decode(secret + "=" * (-len(secret) % 8))Python’s decoder is strict: it rejects lowercase unless asked otherwise and requires padding. Normalizing first, as above, matches what authenticator apps accept.
Best practices
- Write OTP secrets in uppercase without padding, which every authenticator accepts.
- Accept lowercase, spaces and missing padding when reading secrets people typed.
- Reject characters outside the alphabet instead of skipping them.
- Name the variant whenever you exchange Base32 data, since alphabets differ.