Hex vs Base64 vs Base32: RFC 4648 Encodings
RFC 4648 section 10 uses foobar as a test vector for hex, Base64, and Base32. Encoding ASCII foobar writes 666F6F626172 on /base16/. Encoding ASCII foobar writes Zm9vYmFy on /base64/. Encoding ASCII foobar writes MZXW6YTBOI====== on /base32/. Hex here is UTF-8 text-to-hex, not a SHA digest and not sRGB. The live pages are not TOTP verifiers.
Binary data cannot be directly embedded in text formats. These three encodings convert bytes to printable ASCII characters, each with different trade-offs between size, readability, and compatibility.
The same bytes in three encodings
The string foobar (6 ASCII bytes):
RFC 4648 section 10 uses foobar as a test vector for all three encodings.
Encoding comparison
| Property | Hex (Base16) | Base64 | Base32 |
|---|---|---|---|
| RFC 4648 section | Section 8 | Section 4 | Section 6 |
| Alphabet | 0–9 A–F | A–Za–z0–9+/ | A–Z 2–7 |
| Bits per character | 4 | 6 | 5 |
| Size expansion | 2× (100%) | 1.33× (33%) | 1.6× (60%) |
| Case-sensitive | No (typically uppercase) | Yes | No |
| URL-safe | Yes | No (+ and /) | Yes |
| Padding | None | = (0–2 chars) | = (0–6 chars) |
| Human-readable | Best (byte-aligned) | Poor | Good (no confusing chars) |
When to use each encoding
Hex (Base16): Readability and debugging
Every byte becomes exactly 2 hex characters. This 1:2 mapping makes hex ideal when you need to inspect or compare binary data.
- ✓Hash digests – SHA-256 outputs 64 hex characters (32 bytes)
- ✓MAC addresses – 00:1A:2B:3C:4D:5E
- ✓Color codes – #FF5500, rgb(255, 85, 0)
- ✓Protocol debugging – hex dumps of network packets
- ✓UUIDs – 550e8400-e29b-41d4-a716-446655440000
Base64: Compact binary-to-text
The most space-efficient standard encoding. Use when size matters more than human readability.
- ✓Email attachments – MIME encodes binaries in Base64
- ✓Data URIs –
data:image/png;base64,... - ✓PEM certificates –
-----BEGIN CERTIFICATE----- - ✓JSON payloads – embedding binary in APIs
- ✓Basic auth headers –
Authorization: Basic dXNlcjpwYXNz
For URLs and JWTs, use Base64URL instead (- and _ replace + and /).
Base32: Human-friendly secrets
Larger than Base64, but case-insensitive and avoids confusing characters (no 0/O, 1/I/L). Ideal when humans type or speak the encoded value.
- ✓TOTP secrets – Google Authenticator, Authy backup codes
- ✓Recovery codes – 2FA backup codes users must type
- ✓Onion addresses – Tor .onion domains use Base32
- ✓Case-insensitive storage – some file systems, DNS
- ✓URL-safe identifiers – no special characters needed
Size comparison example
Encoding 100 bytes of binary data:
For a 1 MB file, the difference is significant: 2 MB hex, 1.33 MB Base64, 1.6 MB Base32.
Quick reference
- Need smallest size? → Base64
- Need to read individual bytes? → Hex
- Need case-insensitive? → Base32
- Need URL-safe? → Base32 or Base64URL
- Users will type it? → Base32
- Email/MIME attachment? → Base64
- Hash or checksum display? → Hex
Try all three encodings
Encode and decode with hex, Base64, or Base32. Nothing is uploaded.
FAQ
- Which encoding is most compact?
- Base64 is most compact (33% expansion). Base32 expands 60%. Hex (Base16) doubles the size (100% expansion).
- Which encoding is safest for filenames?
- Base32 uses only A-Z and 2-7, avoiding case sensitivity issues. Base64URL is also filename-safe.
- Can I convert between these formats?
- Yes. Decode from one format, then encode to another. The underlying bytes are the same.
- Does this tool upload my data?
- No. All encoding runs in your browser using JavaScript. Nothing is sent to a server.
Related
- Base64 vs Base64URL: URL-Safe Alphabet
- RFC 4648 Base32 vs Base32hex: Alphabet and Sort Order
- SHA-256 vs SHA-1 vs MD5: Differences and Which to Use
- Encode Text to Base64: btoa + UTF-8
- Decode Base64 to UTF-8: atob
- Convert a File to Base64: FileReader
- sRGB Hex vs rgb() vs hsl(): Same Triple, Three Spellings
- Positional BigInt vs Number.parseInt
- Live tools: Hex · Base64 · Base64URL · Base32 · Base32hex · Hash generator