Turn a database ID into a short code
1234567890
1LY7VK
A 10-digit number becomes 6 characters. With 6 characters, Base62 can count to about 56.8 billion.
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.
0-9 A-Z a-z is the most common (GMP, PHP, most libraries); some systems use 0-9 a-z A-Z.1234567890
1LY7VK
A 10-digit number becomes 6 characters. With 6 characters, Base62 can count to about 56.8 billion.
zz
3843
z is 61, so zz = 61 × 62 + 61 = 3843, the largest 2-character value.
Hi
4oz
The bytes 48 69 form the number 18537, which is 4 × 3844 + 50 × 62 + 61, written 4, o, z.
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.
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:
| Step | Value | ÷ 62 | Remainder | Character |
|---|---|---|---|---|
| 1 | 18537 | 298 | 61 | z |
| 2 | 298 | 4 | 50 | o |
| 3 | 4 | 0 | 4 | 4 |
Reading the characters from the last step to the first gives 4oz. Decoding multiplies back up: 4 × 62² + 50 × 62 + 61 = 18537.
| Order | Value 10 | Value 36 | Used by |
|---|---|---|---|
0-9 A-Z a-z | A | a | GMP, PHP gmp_strval(), most libraries |
0-9 a-z A-Z | a | A | Some 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.
| Length | Distinct values (62n) |
|---|---|
| 4 | 14,776,336 |
| 5 | 916,132,832 |
| 6 | 56,800,235,584 |
| 7 | 3,521,614,606,208 |
| 8 | 218,340,105,584,896 |
Six characters cover more than 56 billion IDs, which is why many short links are 6 or 7 characters long.
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:
g8, anyone can try g9. For private links, use random IDs (for example 8 random Base62 characters), not encoded counters.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.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.
// 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"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"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 nThe 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.
Only 0–9, A–Z and a–z: 10 digits plus 26 uppercase and 26 lowercase letters. No +, /, -, _ or =.
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.
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.
Yes. Uppercase and lowercase letters are different digits, so A is 10 and a is 36 in the common alphabet order.
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.
Free, private developer tools that run in your browser. No signup, nothing uploaded, no waiting.
Tip: press Ctrl D to bookmark dev247.