Base62 Encoder and Decoder

Convert text, hex bytes or files to Base62 and back. The output contains only digits and letters, so it is safe in URLs, file names and identifiers without escaping.

Runs entirely in your browser. Nothing is uploaded.

How to use

  1. Choose Encode to turn text into Base62, or Decode to turn Base62 back into text.
  2. Pick the alphabet order that matches your system: 0-9 A-Z a-z (default) or 0-9 a-z A-Z.
  3. Type or paste your input, or open a small file (up to about 20 KB).
  4. Copy the result or download it as a file.

What is Base62?

Base62 uses the ten digits, the 26 uppercase letters and the 26 lowercase letters. It is the largest alphabet made only of letters and digits, so the result needs no escaping in URLs, file names, database keys or identifiers in code. Each character carries about 5.95 bits, which makes the output about 1.34 times the size of the input, nearly as compact as Base64 but without +, /, =, - or _.

Because 62 is not a power of two, this tool treats the whole input as one big number and converts it to base 62, like Base58 and Base36. Each leading zero byte is written as a leading 0 so that it survives the round trip. Input is limited to about 20 KB because the arithmetic slows down for large data.

There is no single Base62 standard

Unlike Base64, Base62 has no RFC, and implementations differ in ways that make their output incompatible:

  • Alphabet order. This tool offers 0-9A-Za-z (the default) and 0-9a-zA-Z. Some other libraries put the letters before the digits.
  • Leading zeros. Some implementations keep one 0 per leading zero byte, as this tool does, some drop them, and fixed-length formats pad the result to a set width.
  • What is encoded. Many Base62 functions encode an integer, such as a database ID, rather than a sequence of bytes. Others split data into fixed-size blocks.

If a string from another system decodes to garbage here, try the other alphabet option. If it still fails, that system probably uses a different method.

Where Base62 is used

URL shorteners turn an auto-incrementing ID into a short code: seven Base62 characters cover more than 3.5 trillion values. Sortable IDs such as KSUID use a fixed 27-character Base62 form, and many services use Base62 for API keys and tokens because a double click selects the whole string and it can be pasted anywhere. To convert a single integer, use the number base converter, or a few lines of code:

// JavaScript: integer (BigInt) to Base62
const A = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
function toBase62(n) {
  let s = '';
  do { s = A[Number(n % 62n)] + s; n /= 62n; } while (n > 0n);
  return s;
}
toBase62(123456789n);   // '8M0kX'

Specification

Alphabet0-9 A-Z a-z
Output sizeAbout 134% (big-number conversion)
PaddingNone
StandardNo formal standard
Case sensitiveYes

Examples

Input (UTF-8)Output
Hello, World!1wJfrzvdbtXUOlUjUf
Base64.isNWxjrFq4r3rv
你好19PqtKE1t

Frequently asked questions

Is Base62 URL-safe?
Yes. It uses only A-Z, a-z and 0-9, which never need escaping in URLs. Base64URL is URL-safe too, but it includes the - and _ characters.
Why does my Base62 string decode to the wrong text?

Base62 implementations differ in alphabet order and method. Switch between the 0-9A-Za-z and 0-9a-zA-Z alphabets. If neither works, the string was probably made from an integer or with another algorithm.

Is Base62 case sensitive?

Yes. Uppercase and lowercase letters stand for different values, so a Base62 string must never be converted to upper- or lowercase.

Should I use Base62 or Base58?
Base58 leaves out 0, O, I and l so that people do not confuse them when copying by hand. Base62 keeps all letters and digits and is slightly shorter. Choose Base58 for strings people type and Base62 for strings that machines handle.