Skip to content

↑↓ navigate ↵ open Esc close Search runs locally

Base62 Encode & Decode Online (Numbers and Text)

Convert numbers or text to Base62 and back. Base62 uses only letters and digits, so it is perfect for short URLs, compact IDs and anything that must stay URL-safe.

  • Runs in your browser
  • Nothing is uploaded
  • Free, no sign-up
0 BUTF-8
Base62
Runs in your browser. Nothing is uploaded. Tip: drop a file onto the left box

How to use the Base62 tool#

  1. Choose Encode or Decode at the top of the tool.
  2. Set Input to Number to convert a whole number (such as a database ID) into a short Base62 string, or to Text / bytes to encode text.
  3. Pick the Alphabet order. 0-9 A-Z a-z is the most common (GMP, PHP, most libraries); some systems use 0-9 a-z A-Z.
  4. Type or paste into the left box, then copy the result.

Examples#

Turn a database ID into a short code

Input
1234567890
Output
1LY7VK

A 10-digit number becomes 6 characters. With 6 characters, Base62 can count to about 56.8 billion.

Decode a short code back to a number

Input
zz
Output
3843

z is 61, so zz = 61 × 62 + 61 = 3843, the largest 2-character value.

Encode text

Input
Hi
Output
4oz

The bytes 48 69 form the number 18537, which is 4 × 3844 + 50 × 62 + 61, written 4, o, z.

What is Base62?#

Base62 writes numbers and data using only the 62 alphanumeric characters: 0–9, A–Z and a–z. There are no symbols at all, so a Base62 string is safe in URLs, file names, HTML attributes and database keys without any escaping. That makes it the usual choice for short links and compact public IDs.

Base62 is most often used for numbers: an auto-increment ID such as 1234567890 becomes 1LY7VK. It can also encode text and bytes, as this tool does in Text / bytes mode.

How Base62 works#

Base62 is ordinary base conversion, the same idea as writing a number in binary or hex, but with 62 digits. To encode a number, divide by 62 repeatedly and write the remainders in reverse:

StepValue÷ 62RemainderCharacter
11853729861z
2298450o
34044

Reading the characters from the last step to the first gives 4oz. Decoding multiplies back up: 4 × 62² + 50 × 62 + 61 = 18537.

The two alphabet orders#

OrderValue 10Value 36Used by
0-9 A-Z a-zAaGMP, PHP gmp_strval(), most libraries
0-9 a-z A-ZaASome URL shorteners and ID libraries

There is no single official standard, so both sides of a system must agree on the order. If a decoded number looks wrong, try the other order first.

How many IDs fit in N characters?#

LengthDistinct values (62n)
414,776,336
5916,132,832
656,800,235,584
73,521,614,606,208
8218,340,105,584,896

Six characters cover more than 56 billion IDs, which is why many short links are 6 or 7 characters long.

Base62 for short URLs#

A typical URL shortener stores each link with an auto-increment ID and encodes that ID in Base62 for the public link. Two things to keep in mind:

  • Sequential IDs are guessable. If link 1000 is g8, anyone can try g9. For private links, use random IDs (for example 8 random Base62 characters), not encoded counters.
  • Case matters. a and A are different values, so Base62 IDs break in systems that change case, such as some email clients or case-insensitive databases. Use Base36 if that is a risk.

Numbers vs bytes#

In Number mode, the input is a decimal integer of any size. In Text / bytes mode, the input is converted to UTF-8 bytes, which are read as one big number and converted the same way, with leading zero bytes kept as leading 0 characters. Bytes need about 34% more space in Base62, about the same as Base64, but without any symbols.

Base62 in code#

PHP (GMP)#

php
// GMP uses 0-9 A-Z a-z for bases 37–62$code = gmp_strval(gmp_init('1234567890', 10), 62);   // "1LY7VK"$id   = gmp_strval(gmp_init('1LY7VK', 62), 10);      // "1234567890"

JavaScript#

javascript
const ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; function toBase62(n) {  n = BigInt(n);  if (n === 0n) return '0';  let out = '';  while (n > 0n) { out = ALPHABET[Number(n % 62n)] + out; n /= 62n; }  return out;} function fromBase62(s) {  return [...s].reduce((n, c) => n * 62n + BigInt(ALPHABET.indexOf(c)), 0n);} toBase62(1234567890); // "1LY7VK"

Python#

python
ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' def to_base62(n: int) -> str:    out = ''    while True:        n, r = divmod(n, 62)        out = ALPHABET[r] + out        if n == 0:            return out def from_base62(s: str) -> int:    n = 0    for c in s:        n = n * 62 + ALPHABET.index(c)    return n

Common errors and fixes#

  • The decoded number is completely different from the original

    The encoder and decoder use different alphabet orders (0-9 A-Z a-z vs 0-9 a-z A-Z). Switch the Alphabet option and decode again.

  • Large IDs decode to the wrong value in JavaScript

    JavaScript numbers lose precision above 2⁵³ (9,007,199,254,740,991). Use BigInt, as in the example above. This tool uses BigInt, so any size works.

  • "Enter a whole, non-negative number"

    Number mode only accepts the digits 0–9. Remove decimals, minus signs and letters. Commas, spaces and underscores are allowed and ignored.

  • Short links stop working after passing through another system

    Something changed the letter case. Base62 is case-sensitive, so aB3 and ab3 are different IDs. Use Base36 if your IDs pass through case-insensitive systems.

Frequently asked questions#

What characters does Base62 use?

Only 0–9, A–Z and a–z: 10 digits plus 26 uppercase and 26 lowercase letters. No +, /, -, _ or =.

Is Base62 better than Base64 for URLs?

For IDs and short codes, yes: it needs no special characters at all. For large binary data, Base64URL is faster and standardised, so it is the better choice there.

How do I convert a number to Base62?

Set Input to Number, choose Encode and type the number. 1234567890 becomes 1LY7VK. Divide by 62 repeatedly and map each remainder to a character to do it in code.

Is Base62 case-sensitive?

Yes. Uppercase and lowercase letters are different digits, so A is 10 and a is 36 in the common alphabet order.

Is there an official Base62 standard?

No. Unlike Base64 and Base32, Base62 has no RFC, which is why two alphabet orders are in use. Pick one and use it everywhere in your system.

Your next tool is one search away.

Free, private developer tools that run in your browser. No signup, nothing uploaded, no waiting.

Browse all tools

Tip: press Ctrl D to bookmark dev247.