What Is Base32? Base32 vs Base64, Step-by-Step Encoding and TOTP Keys
Updated: November 6, 2026 · AracMerkezi
Base32 is an encoding that writes binary data using an alphabet of just 32 characters: uppercase letters and digits. You use it when you need to carry a byte sequence into a place that expects text, such as a configuration file, a QR code, a form field or an email. Instead of asking you to memorize the alphabet, this guide encodes by hand at the bit level, compares the size of three encodings with real numbers, and explains why two-factor authentication (TOTP) secrets look like Base32.
The alphabet and basic rules
Base32 is defined in RFC 4648 and consists of the letters A–Z and the digits 2–7, 32 characters in total. The digits 0, 1, 8 and 9 are left out on purpose because they can be confused with letters such as O, I and B. The result is fewer mistakes in keys that are copied from paper or read aloud over the phone. Each character carries exactly 5 bits (2⁵ = 32). The encoding table runs A = 0, B = 1 ... Z = 25, 2 = 26 ... 7 = 31.
Step by step: how does "foo" become MZXW6===?
Let's work through an example by hand. The input is the three-letter text foo:
- Write each letter's ASCII byte value as 8 bits:
f= 01100110,o= 01101111,o= 01101111. That is 24 bits in total. - Line the bits up and split them into groups of 5: 01100 · 11001 · 10111 · 10110 · 1111
- The last group has only 4 bits; pad it on the right with a zero to make 5 bits: 11110.
- Convert each group to a number: 12, 25, 23, 22, 30.
- Look them up in the alphabet: 12 = M, 25 = Z, 23 = X, 22 = W, 30 = 6. The result is
MZXW6. - The output length must be a multiple of 8. We wrote 5 characters, so the remaining 3 positions are filled with
=:MZXW6===.
In Python, base64.b32encode(b"foo") returns the same result. The other examples in RFC 4648 follow the same logic: f → MY======, fo → MZXQ====, foobar → MZXW6YTBOI======.
Decoding works the same way in reverse. To decode MZXQ====, first drop the = signs. The remaining characters M, Z, X, Q are the numbers 12, 25, 23, 16; written as 5-bit groups they give 01100 · 11001 · 10111 · 10000, which is 20 bits. The first 16 of those bits are 01100110 01101111 (f and o); the 4 leftover bits came from padding, so they are discarded and the result is fo.
Size comparison: Base32, Base64 and hex
5 bytes (40 bits) make exactly 8 Base32 characters, so the ratio is 8/5 = 1.6. In Base64, 3 bytes become 4 characters, so the ratio is 4/3 ≈ 1.33; in hex every byte is 2 characters, so the ratio is 2. The actual character counts including padding (the values below were calculated and verified with Python):
| Raw data | Base32 (padded) | Base64 (padded) | Hex |
|---|---|---|---|
| 5 bytes | 8 | 8 | 10 |
| 10 bytes | 16 | 16 | 20 |
| 20 bytes | 32 | 28 | 40 |
| 100 bytes | 160 | 136 | 200 |
The takeaway from the table: Base32 is always longer than Base64 but shorter than hex. If size is critical, Base64 makes sense; if readability and case-independence are critical, Base32 does.
Example: a two-factor authentication (TOTP) key
The secret key you type into an authenticator app often looks like JBSWY3DPEHPK3PXP. That is a Base32 string; decoded, it becomes a 10-byte raw key (this sample key is a demo widely used in documentation, so never use it on a real account). Apps usually carry the key inside a link of this form: otpauth://totp/Example:ali@example.com?secret=JBSWY3DPEHPK3PXP&issuer=Example. The QR code contains the same text.
Why Base32? The app and the server must hold exactly the same bytes. In text typed by hand, mixed-up letter case and look-alike characters cause trouble, and Base32 reduces both. In the RFC 6238 test example, the raw key is the ASCII text 12345678901234567890; its Base32 form is GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ. With this key, Unix time 59 produces the 8-digit SHA-1 based code 94287082; we calculated it with our own code and matched it to the RFC value.
Base32 variants
| Variant | Alphabet | Note |
|---|---|---|
| RFC 4648 standard | A–Z, 2–7 | The most common one; used for TOTP keys |
| Base32hex (RFC 4648) | 0–9, A–V | Preserves sort order; foo → CPNMU=== |
| Crockford | 0–9 and letters (no I, L, O, U) | Designed for readability, a different definition |
The same byte sequence gives different text in a different alphabet. Use whichever variant a system expects; most tools and libraries default to the standard alphabet.
Common mistakes
- Mistaking encoding for encryption. Base32 is a keyless, fully reversible transformation; anyone can decode
MZXW6YTBOI======. Saying "I stored the password as Base32" provides no security. - Handling padding wrongly. Python's
b32decoderaises "Incorrect padding" for the unpadded inputMZXW6YTBOI; add=to the end andfoobarcomes back. Some applications accept unpadded keys and some do not. - Working in lowercase. The standard alphabet is uppercase, and depending on the library, lowercase may raise an error. Convert to uppercase first.
- Not stripping spaces and dashes. If a key was grouped in fours for readability, remove the separators before decoding.
- Sharing a TOTP key like ordinary text. Anyone who knows the secret can generate the same codes; leaving it in a screenshot, a chat message or an open note has the same effect as sharing a password.
- Expecting text as output. If the decoded bytes are a binary key, they may not be valid UTF-8; that is normal.
When to use Base32, Base64 or hex
- Base32 for environments where text is typed by hand, read aloud or where letter case is not distinguished (some file systems, for example).
- Base64 when size and efficiency matter, especially in APIs and data URIs.
- Hex when you want to see byte values one to one while debugging; because every two characters show one byte, it is the easiest to convert in your head.
- If a protocol or library requires a specific encoding, follow the choice in its documentation, whatever your own preference for size or readability.
Mini glossary
- Encoding: Converting data to another representation; it provides no secrecy.
- Padding: The
=characters that bring the output up to the block size. - TOTP: Time-based one-time password; generated from a secret key and the clock.
- Bit group: The 5-bit piece in Base32; each one becomes one character.
Tools
The Base32 Encode/Decode tool converts text to Base32 and decodes it, with optional padding. For comparison use the Base64 Encode/Decode tool, and to see the bit level use the Number Base Converter. For other encodings, the JSON, Base64 and URL encode guide and the guide to binary, decimal and hexadecimal number systems are helpful.
Frequently asked questions
Is Base32 encryption?
No; it is a keyless, reversible encoding. It should not be used to protect secret data.
How much bigger is Base32 than Base64?
Base32 expands data to 8/5 = 1.6 times its size and Base64 to 4/3 ≈ 1.33 times, so Base32 output is roughly 20% longer than Base64.
What is the = sign at the end of Base32 for?
It is padding that brings the output length up to a multiple of 8. Some systems accept keys without padding, while others expect it.
Tools mentioned in this guide
More guides
- How to Convert HEX to RGB Color Codes: Step-by-Step Examples – How to convert a HEX color code to RGB and back: hexadecimal basics, short and 8-digit HEX, darkening math and verified JavaScript and Python snippets.
- What Are ROT13 and the Caesar Cipher? Worked Example, Cracking Method and Limits – Caesar cipher and ROT13 step by step: a MERHABA example, the 29-letter Turkish alphabet, cracking by trying 25 keys, frequency analysis, one-line code.
- Binary, Decimal and Hexadecimal Number Systems: Methods for Converting Between Bases – How do you convert between binary, octal, decimal and hexadecimal? The division and grouping methods, bit limits and worked examples.
- How to Create a Secure Password: Length, Entropy and 8 Rules – How to create a secure password: password strength in bits, random-word passphrases, command-line generation and eight practical rules.
- What Are JSON, Base64 and URL Encoding? Encoding vs Encryption vs Hashing – What do JSON, Base64, URL encoding, HTML entities, SHA and JWT do? Encoding vs encryption vs hashing, with examples that were run and verified.
This article is for general information only and is not legal, financial or medical advice. We are not an official institution.