Base64 vs Base62: Which Encoding to Use Where
Abhay Khant
Jan 1, 1970 • 5 min read
Base64 vs Base62: Which Encoding to Use Where
- Base64 packs data at 6 bits per character; base62 manages 5.954, a tiny density gap
- The real difference is the alphabet: base64 uses +, /, and =; base62 sticks to letters and digits
- Base64 is standardized in RFC 4648; base62 has no standard, so implementations vary
- Pick by destination: binary transport wants base64, URLs and human-facing IDs want base62
Two alphabets, two jobs
Both encodings answer the same problem [MDN describes directly](https://developer.mozilla.org/en-US/docs/Glossary/Base64): moving binary data through systems that only handle text. [Base64](https://en.wikipedia.org/wiki/Base64) solves it with a 64-character alphabet of A to Z, a to z, 0 to 9, plus and slash, with equals signs padding the end. It is formally specified in [RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648), which also defines the URL-safe variant swapping minus and underscore for plus and slash.
[Base62](https://en.wikipedia.org/wiki/Base62) drops the special characters entirely and uses only 0 to 9, a to z, and A to Z. No RFC defines it; it began as a convention popularized by URL shorteners and persists as shared folklore implemented slightly differently everywhere. That missing standard is the single most important fact about base62, more consequential than any compression arithmetic.
The same value encoded both ways
We encoded one 128-bit value during research for this guide so the numbers are real output rather than theory:
| Encoding | Output | Length |
|---|---|---|
| Hexadecimal | 0123456789abcdef0123456789abcdef | 32 chars |
| Base64 | ASNFZ4mrze8BI0VniavN7w== | 24 chars |
| Base64 unpadded | ASNFZ4mrze8BI0VniavN7w | 22 chars |
| Base64url unpadded | ASNFZ4mrze8BI0VniavN7w | 22 chars |
| Base62 | 296tiiBb3U904RIpygpjj | 21 chars |
The honest headline sits in that last row: base62 saved exactly one character over unpadded base64 on a 128-bit value. Each base64 character carries 6 bits while each base62 character carries about 5.954, because log2(62) falls just short of 6; the [base64 overview on Wikipedia](https://en.wikipedia.org/wiki/Base64) shows the same arithmetic for padding behavior. If you are choosing base62 to make identifiers dramatically shorter, the arithmetic will disappoint; choose it for its alphabet instead.
The URL problem base62 was born to solve
Standard base64 embeds three characters that URLs treat specially. Plus becomes a space in form decoding, slash breaks path parsing, and equals padding confuses query-string handling. We demonstrated the damage concretely during research: encoding three hostile bytes produced +/++ in standard base64, which percent-encoding then inflated to %2B/%2B%2B. The [URI specification, RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986), reserves those punctuation marks for structural meaning, so unescaped base64 inside a path is a latent bug rather than a style choice.
Two fixes exist. The [URL-safe base64 variant defined in RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648#section-5) replaces plus and slash with minus and underscore, keeping full binary fidelity for machine-to-machine links. Base62 goes further and removes the problem class entirely: an identifier made only of letters and digits survives copy-paste from print, double-click selection, spreadsheet cells, and human dictation without escaping anywhere.
What the missing standard costs
Base64 has one correct answer for any input, verified against test vectors in the RFC. Base62 implementations differ in alphabet order (digits first or letters first), in how they treat leading zeros, and in whether they encode raw bytes or big integers. Decode 296tiiBb3U904RIpygpjj with a library that assumes a different digit ordering and you get garbage or an error instead of your identifier back.
The [base62 write-up on Wikipedia](https://en.wikipedia.org/wiki/Base62) catalogs implementations that disagree on alphabet ordering, so teams adopting it write the alphabet down: pin the exact character sequence, document leading-zero behavior, and add round-trip tests before the second service ever parses a base62 value. None of this is hard; all of it is necessary precisely because no RFC exists to lean on.
Choosing between them
| Use case | Better fit |
|---|---|
| Email attachments, data URIs, Authorization headers | Base64, always: standards exist here |
| Binary inside JSON APIs | Standard or URL-safe base64 |
| Short link slugs and shareable IDs | Base62 |
| Human-typed codes on invoices or coupons | Base62, often minus ambiguous glyphs |
| Anything another team must decode blind | Base64, because the RFC travels well |
Working with both daily
- Convert text or files in either direction with the base64 encoder and decoder, including the URL-safe variant
- Check whether your base64 payloads contain plus, slash, or padding before placing them in URLs
- For JWT work, remember tokens use base64url already; our [JWT decoding guide](/blog/decode-jwt-token-online/) covers the segment format
- When building a base62 system, encode a known vector and store the expected output beside the code as a regression test
Alphabet beats arithmetic
Base64 vs base62 is not a size contest; the density difference rounds away to noise. It is a question of destination. Where machines exchange bytes under a written standard, base64 wins on interoperability alone. Where humans read, type, and share short identifiers across media that mangle punctuation, base62's pure alphanumeric alphabet earns its keep despite the absent spec. Choose by consumer, document your alphabet, and both encodings behave.


