Comparison

Base62 vs Base64 // toBase62()

How Base62 differs from Base64, when URL shorteners use it, and a free number-to-Base62 converter.

🛡 100% client-side ⚡ Instant
🔒 Privacy First: All conversion happens locally in your browser. Your data never leaves your device.

Bonus tool: convert a non-negative integer (e.g. a database ID) to Base62 and back — the same technique URL shorteners use to turn 12345 into a short code.

What Is Base62?

Base62 is a binary-to-text encoding that represents data using 62 characters: 0-9, A-Z, and a-z. Unlike Base64, it uses no special characters (no +, /, or = padding), which makes every Base62 string automatically safe to use in URLs, filenames, and database keys without any escaping.

There's no single RFC for Base62 — it's typically implemented as straight positional-numeral-system conversion, the same idea as converting a decimal number to hexadecimal, just with a 62-character alphabet instead of 16. That's different from Base64, which processes data in fixed 3-byte-to-4-character blocks.

Base62 vs Base64: Key Differences

PropertyBase62Base64
Alphabet0-9, A-Z, a-z (62 chars)A-Z, a-z, 0-9, +, / (64 chars)
PaddingNone= (multiple of 4)
URL-safe by defaultYesNo (needs the URL-safe variant)
Encoding methodPositional numeral conversion (like hex)Fixed 3-byte → 4-character blocks
Standardized (RFC)NoYes (RFC 4648)
Typical inputIntegers (IDs, counters)Arbitrary binary data (files, images, text)
Common use caseShort URLs, order/invoice codesEmbedding files, API payloads, data URIs

Why Do URL Shorteners Use Base62?

Services like Bitly and TinyURL assign each link an auto-incrementing database ID, then convert that integer to Base62 to produce the short code in the URL — id 125000 becomes something like 8Q0. Because the alphabet excludes +, /, and other reserved URL characters, the result never needs percent-encoding. Base64 can't do this directly for the same reason it needs a URL-safe variant in the first place.

Try the converter above: enter an integer to see its Base62 code, or paste a Base62 code to recover the original number.

How Does Base62 Encoding Work?

Base62 encoding repeatedly divides the input number by 62, using the remainder at each step to look up a character in the alphabet, then reverses the resulting digit sequence — the same algorithm you'd use to convert a decimal number to any other base.

JavaScript
const ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

function toBase62(n) {
  if (n === 0n) return '0';
  let out = '';
  while (n > 0n) {
    out = ALPHABET[Number(n % 62n)] + out;
    n = n / 62n;
  }
  return out;
}

function fromBase62(s) {
  let n = 0n;
  for (const ch of s) n = n * 62n + BigInt(ALPHABET.indexOf(ch));
  return n;
}

Because Base62 operates on the number as a whole rather than fixed byte blocks, encoding text requires first converting the text's bytes into one large integer (or using a per-character mapping) — it isn't a drop-in replacement for encoding arbitrary binary files the way Base64 file encoding is.

When Should You Use Base62 Instead of Base64?

Choose Base62 when you're encoding a number (a database ID, counter, or hash-derived integer) into a short, URL-safe, human-typeable string — short links, invite codes, order references, or shard/partition keys. Choose Base64 when you're encoding arbitrary binary data (images, files, JSON payloads) that needs a lossless, standardized, reversible text representation. The two aren't really interchangeable: Base62 shines at compressing small integers into short strings, while Base64 is built for streaming raw bytes through text-only channels.

Frequently Asked Questions

Is Base62 more secure than Base64?

Neither is a security mechanism — both are reversible encodings, not encryption. Anyone can decode a Base62 or Base64 string with no key. Base62 short codes are only "hidden" in the sense that they're hard to guess sequentially if you also add randomness; the encoding itself provides no confidentiality.

Is Base62 shorter than Base64?

For the same integer value, Base62 and Base64 produce similar lengths since 62 and 64 are close in size (about 5.95 vs 6 bits per character). The real advantage of Base62 isn't shortness — it's that the output never contains URL-unsafe characters.

Can I use Base62 to encode a whole file?

Technically yes — treat the file's bytes as one giant integer — but it's impractical. Base62's math gets extremely slow on large numbers, and there's no standard chunking scheme like Base64's 3-byte blocks. For files and binary data, use Base64 instead.

What is Base58, and how does it compare?

Base58 (used by Bitcoin addresses) is Base62 with 4 more characters removed — 0, O, I, and l — to avoid visual ambiguity when people read or type codes by hand. It trades a little compactness for fewer transcription errors, similar to why Base32 excludes ambiguous characters too.