Skip to content

Base32 encoder and decoder

Encode text or bytes as Base32, or decode Base32 back to text and hex, following RFC 4648.

Runs in your browser. Nothing you paste is sent to us.

Input

A sample text is filled in. Type or paste your own.

Output

27 bytes

Base32
JBSWY3DPEBTHE33NEBQXK5DIFZSXQYLNOBWGKLTDN5WQ====
RFC 4648 Base32 uses A to Z and 2 to 7. One-time password secrets are usually shown this way, often without padding.

How to use it

  1. Choose Encode or Decode.
  2. Paste the text, hex bytes or Base32.
  3. Choose whether to add = padding when encoding.
  4. Copy the result.

What to know

Base32 writes bytes with the letters A to Z and the digits 2 to 7. It avoids 0, 1 and 8, which look like O, I and B, so people can read and type it.

One-time password secrets are shared in Base32, often in lowercase groups and without padding. The decoder accepts those forms.

This is the RFC 4648 alphabet. Crockford’s Base32 and the base32hex variant use different alphabets and give different results.

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.

Encoding "foo" step by step
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===
ValuesCharacters
0 to 25A to Z
26 to 312 to 7
Padding=

The RFC 4648 test vectors

InputBase32
(empty)(empty)
fMY======
foMZXQ====
fooMZXW6===
foobMZXW6YQ=
foobaMZXW6YTB
foobarMZXW6YTBOI======

This tool reproduces all of these, both encoding and decoding.

Base32 compared with Base64 and hex

EncodingBits per characterSize of 20 bytesCase-sensitiveTypical use
Hex (Base16)440 charactersNoHashes, keys in logs
Base32532 charactersNoOTP secrets, human-typed codes
Base64628 charactersYesBinary in text formats, PEM
Base64url627 charactersYesTokens, 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

  1. Choose Encode or Decode. Switching carries the current result across, so you can round-trip.
  2. To encode, choose text or hex input and paste the data.
  3. To decode, paste the Base32. Grouped, lowercase text is fine.
  4. 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 groupCharactersPaddingUnpadded length mod 8
58none0
47=7
35===5
24====4
12======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.

Base32 with Python’s standard 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.
Questions

Frequently asked questions

What characters does Base32 use?

RFC 4648 Base32 uses the 26 uppercase letters A to Z and the digits 2 to 7, plus = for padding. Lowercase letters are accepted when decoding.

Why do 2FA apps use Base32 for secrets?

Base32 is case-insensitive and avoids 0, 1 and 8, which are easily confused with O, I and B. That makes secrets easier to read and type when a QR code cannot be scanned.

Is the = padding required in Base32?

RFC 4648 includes it, but OTP secrets are usually written without it. This decoder accepts both.

What is the difference between Base32 and Base64?

Base64 packs 6 bits per character and is case-sensitive; Base32 packs 5 bits and is not. Base32 is about 20 percent longer than Base64 for the same data, in exchange for being easier for people to handle.

Why does my Base32 string fail to decode?

It may contain characters outside the alphabet, often 0, 1 or 8, or a character may be missing. It could also use a different alphabet, such as base32hex or Crockford’s Base32.

Is Base32 encryption?

No. It is a reversible encoding with no key. Anything encoded in Base32 can be decoded by anyone.

How long is a Base32 OTP secret?

A 160-bit secret, 20 bytes, is 32 Base32 characters without padding. A 128-bit secret, 16 bytes, is 26 characters without padding.

How do I decode Base32 in Python?

Use base64.b32decode from the standard library. It expects uppercase and padding, so for OTP secrets remove spaces, convert to uppercase and add = until the length is a multiple of 8 before decoding.

Can Base32 be used in URLs and file names?

Yes. Its letters and digits are safe in URLs and file names, though the = padding may need encoding in a URL, so leave it out there. Because it is case-insensitive, it also survives systems that change case.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.