Base32 Decode
Base32 decoder: each character stands for five bits, so JBSWY3DP decodes to the five bytes of Hello. Paste a Base32 string and read it as text; padding, case and the base32hex and Crockford alphabets are handled, and bad characters are reported by position. Text to Base32 works too.
Base32 decoding: five bits per character
Base32 writes binary data using 32 characters, and 32 is 2 to the power 5, so every character stands for exactly five bits. To decode a Base32 string you look up the 5-bit value of each character, join all the bits in order, and cut the long bit string into groups of eight, because a byte has eight bits. The result is the original data, which can be text, a key or any other bytes. The converter above decodes as you type and shows the bytes as text in the encoding you choose.
The two bytes of Hi are 16 bits, which is three groups of five bits and one more bit. The last group is filled with zeros to reach five, so four characters are produced, J, B, U and Q, and the rest of the block is padded with = signs. Decoding runs this backwards and throws the filler zeros away. The conversion is lossless and reversible, which makes Base32 an encoding and not a cipher.
The RFC 4648 alphabet
The standard alphabet, defined in RFC 4648, uses the 26 upper case letters and the digits 2 to 7. Values 0 to 25 are the letters A to Z and values 26 to 31 are the digits 2 to 7. Digits 0, 1, 8 and 9 are left out because they are easy to confuse with the letters O, I and B, which was a design goal for a format that people read and type by hand.
| Values | Characters | Bit patterns |
|---|---|---|
| 0 to 7 | ABCDEFGH | 00000 00001 00010 00011 00100 00101 00110 00111 |
| 8 to 15 | IJKLMNOP | 01000 01001 01010 01011 01100 01101 01110 01111 |
| 16 to 23 | QRSTUVWX | 10000 10001 10010 10011 10100 10101 10110 10111 |
| 24 to 31 | YZ234567 | 11000 11001 11010 11011 11100 11101 11110 11111 |
Decoding a string by hand
Take JBSWY3DP. Its eight characters are 40 bits, which is exactly five bytes, so there is no padding. Look up each character, write its value as five bits, join them and re-cut them into eights.
| Character | Value | 5 bits |
|---|---|---|
| J | 9 | 01001 |
| B | 1 | 00001 |
| S | 18 | 10010 |
| W | 22 | 10110 |
| Y | 24 | 11000 |
| 3 | 27 | 11011 |
| D | 3 | 00011 |
| P | 15 | 01111 |
The joined bits, 01001 00001 10010 10110 11000 11011 00011 01111, regroup as 01001000 01100101 01101100 01101100 01101111, which are the bytes 48 65 6C 6C 6F and spell Hello. The same bytes encode back to JBSWY3DP, which confirms the conversion. For the hex and binary views of the same bytes, paste the text into the text to hex or binary to text converters.
Padding and the length of a Base32 string
Base32 processes five bytes at a time and produces eight characters from them. Data whose length is not a multiple of five leaves a last block that is only partly filled, and the encoder fills the remaining places with = signs so that the string length is a multiple of eight. The number of signs tells you how many bytes are in the last block, and only four lengths of padding are possible: 6, 4, 3 or 1.
| Bytes in last block | Example | Base32 | Characters | = signs |
|---|---|---|---|---|
| 1 | a | ME====== | 2 | 6 |
| 2 | ab | MFRA==== | 4 | 4 |
| 3 | abc | MFRGG=== | 5 | 3 |
| 4 | abcd | MFRGGZA= | 7 | 1 |
| 5 | abcde | MFRGGZDF | 8 | 0 |
When a string has no padding the decoder works out the number of bytes from the character count, which is what the converter does and reports. A character count that cannot come from any number of bytes, such as 1, 3 or 6 characters in the last block, is an error: the message says how many characters are in the last block and which counts are valid.
A few lengths are worth recognising. Ten bytes, the size of a short secret, make 16 characters with no padding. A 16-byte key makes 26 characters plus 6 padding signs, and a 20-byte key, the size of a SHA-1 digest, makes exactly 32 characters. So a Base32 string without padding that is 26 or 32 characters long is often a 16-byte or 20-byte value, and the status line under the input shows the byte count the converter found.
Four alphabets and how the converter chooses
RFC 4648 also defines a second alphabet, base32hex, which uses 0 to 9 and A to V so that the encoded strings sort in the same order as the data. Two further variants are common outside the RFC: Crockford's Base32, which drops the letters I, L, O and U to avoid confusion and treats lookalikes as equal, and z-base-32, which orders its lower case characters to make them easier to read aloud and type. The alphabet menu above lets you pick one. The default, Detect, tries RFC 4648 first and moves to the next alphabet only if a character does not fit.
| Alphabet | Characters | Padding |
|---|---|---|
| RFC 4648 | ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 | = used |
| base32hex (RFC 4648) | 0123456789ABCDEFGHIJKLMNOPQRSTUV | = used |
| Crockford | 0123456789ABCDEFGHJKMNPQRSTVWXYZ | not used |
| z-base-32 | ybndrfg8ejkmcpqxot1uwisza345h769 | not used |
Detection can be ambiguous. A string made only of the digits 2 to 7 and the letters A to V fits both RFC 4648 and base32hex, and the converter reads it as RFC 4648 because that is by far the more common one. If the output looks like noise, switch the alphabet by hand. When the detector has to fall back it says which alphabet it used, so you do not have to guess.
Authenticator app secrets
The most common place people meet Base32 is the secret key behind a time-based one-time password, the six-digit codes in an authenticator app. When a site shows a setup key next to its QR code, that key is the shared secret encoded in Base32, in upper case and usually without padding, and the QR code itself contains an otpauth address with the same string in its secret parameter. Decoding it gives the raw key bytes that go into the code generator.
Treat that secret as a password. Anyone who has it can generate your login codes. This converter works entirely in the page and does not send what you type anywhere, but pasting a live secret into any website is still a bad habit. If you want to see how a secret maps to bytes, use a made-up one or a secret from a test account.
Where else Base32 is used
Base32 is chosen where the text must survive systems that change case or where people have to read it. Version 3 onion addresses of the Tor network are Base32 strings, and the addresses are written in lower case in practice. Identifiers such as ULIDs use Crockford's alphabet, and the geohash string for a map position uses its own 32-character alphabet. File names, DNS labels and URLs are all places where a case-insensitive encoding is safer than Base64, whose upper and lower case letters are different values. The cost is size, discussed next.
Size compared with Base64 and hex
Five bytes become eight characters, so Base32 makes data 60 percent larger. Base64 turns three bytes into four characters, an increase of about 33 percent, and hex writes two characters for every byte, which doubles the size. Base32 is thus the middle choice, larger than Base64 but with an alphabet that is safer for case-insensitive and hand-typed use.
| Data bytes | Hex | Base32 | Base64 |
|---|---|---|---|
| 5 | 10 | 8 | 8 |
| 10 | 20 | 16 | 16 |
| 16 | 32 | 32 | 24 |
| 20 | 40 | 32 | 28 |
| 32 | 64 | 56 | 44 |
| 64 | 128 | 104 | 88 |
If the string you hold is Base64 rather than Base32, the Base64 decoder is the right tool, and for hex use the hex decoder. The auto decoder identifies the common formats from the characters used.
What the decoder reports
An invalid character is named with its position, counting from 1, and in the RFC 4648 alphabet a 0, 1, 8 or 9 gets an extra note that those digits are not part of it. A bad length is reported with the number of characters in the last block. A = sign followed by more data is an error, since padding belongs at the end. A wrong number of = signs is a warning, and missing padding is a note, not an error.
One more check is easy to miss. The last character of an unpadded string can carry bits that are not part of the data, and a strict encoder always sets them to zero. If they are not zero the decoder warns that the unused bits are not zero. The data still decodes, but the string was probably not produced by a standard encoder, which is worth knowing when you debug an interface between two systems.
Encoding text to Base32
The Text to Base32 button reverses the direction. The text is turned into bytes in the encoding you choose, UTF-8 by default, and the bytes are written in the selected alphabet. The padding option controls whether = signs are added. Authenticator secrets are usually written without them, while the RFC examples have them. The Swap button takes the current output as the next input, so you can check that a round trip returns the original text.
Base32 in code
There is no Base32 function in JavaScript's standard library, but a decoder is short. The one below was run, and the coreutils command is available on Linux and in Git Bash.
const A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
function base32Decode(s) {
let bits = "";
for (const c of s.replace(/=+$/, "").toUpperCase()) bits += A.indexOf(c).toString(2).padStart(5, "0");
const bytes = [];
for (let i = 0; i + 8 <= bits.length; i += 8) bytes.push(parseInt(bits.slice(i, i + 8), 2));
return new TextDecoder().decode(Uint8Array.from(bytes));
}
console.log(base32Decode("JBSWY3DPEBLW64TMMQ======")); // Hello Worldecho "JBSWY3DP" | base32 -d
# Hello
printf 'Hi' | base32
# JBUQ====The JavaScript function does no error checking: an invalid character gives an index of -1 and corrupts the result silently. That is the reason to use a decoder that reports problems when the input comes from a user. PowerShell has no built-in Base32 command, so a short function like the one above is the usual approach there.
Base32 is not encryption
Anyone can decode a Base32 string without a key. It is a way to write bytes with letters and digits, and it hides nothing. If a service gives you a Base32 value and says it is secret, the secrecy comes from the value being hard to guess, and not from the encoding. The same holds for Base64 and hex, and the Base64 page makes the point with more examples.
Questions about Base32 decoding
How do I decode a Base32 string?
Replace each character with its 5-bit value from the alphabet (A is 0 to Z is 25, 2 is 26 to 7 is 31), join the bits, and cut them into groups of eight. Each group of eight is one byte. The converter does this and then shows the bytes as text in the chosen encoding.
Why does Base32 end with = signs?
Base32 works in blocks of 8 characters that hold 5 bytes. When the data does not fill the last block, = signs pad it to 8. One byte of data leaves 6 signs, two bytes 4, three bytes 3 and four bytes 1. The decoder accepts input without the padding.
Is Base32 case sensitive?
The standard alphabet is upper case, and most decoders, including this one, accept lower case and read it as upper case. Case-insensitivity is one of the reasons Base32 exists, since it survives systems that fold case, such as DNS and some file systems.
What do 0, 1, 8 and 9 mean in Base32?
Nothing in the standard RFC 4648 alphabet, which uses A to Z and 2 to 7. The digits 0, 1, 8 and 9 are left out because they look like O, I and B. They do appear in the base32hex and Crockford alphabets, and the converter detects those when no letter outside their range is present.
Can I decode my authenticator app secret here?
The decoding happens in your browser and nothing is sent anywhere. Even so, a secret key is a password, so avoid pasting a live one into any web page. Use a sample or a test secret if you only want to see how the key maps to bytes.
