Skip to main content
短.be

Base62 Encoding

An encoding scheme that represents data using 62 alphanumeric characters (a-z, A-Z, 0-9). Widely used to generate short URL codes.

Nov 7, 2025 · About 1 min read

URL Shortening

Base62 encoding represents data using 26 lowercase letters (a-z), 26 uppercase letters (A-Z), and 10 digits (0-9), totaling 62 characters. It is the most widely used technique for generating short URL codes.

Why Base62 suits short URLs can be shown with numbers. A 6-character Base62 code can represent 62^6, roughly 56.8 billion unique patterns. With 7 characters, that jumps to about 3.5 trillion. This capacity would not be exhausted even if every short URL service in the world ran for decades.

Internally, most short URL services assign a unique integer ID to each URL and convert that ID to Base62 to produce the short code. For example, ID 12345 converts to "3d7" (3 characters). Codes grow longer as IDs increase, but values up to tens of billions still fit within 6 characters.

Base64 is a similar scheme, but it includes "+" and "/", which have special meanings in URLs and require percent-encoding. Base62 uses only URL-safe characters, so no additional encoding is needed. This is why Base62 is preferred for short URLs.

Implementing Base62 is straightforward: it is simply a base-10 to base-62 conversion, achievable in a few lines of code in most languages. One caveat: converting sequential IDs directly to Base62 makes codes predictable, which is a security concern. Common countermeasures include adding a random offset to the ID or combining it with a hash function. Related books are available on Amazon.

Share on XHatena

Was this article helpful?

Related Terms

Related Articles

FAQ

What is the difference between Base62 and Base64?
Base64 uses 64 characters (alphanumerics plus "+" and "/"). Because "+" and "/" carry special meaning in URLs, they require percent-encoding. Base62 uses only alphanumeric characters, so it can be embedded in URLs as-is, making it ideal for short URLs.
How many characters is a typical Base62 short code?
Six to seven characters is standard. Six characters yield about 56.8 billion patterns and seven about 3.5 trillion, which is more than enough even for large-scale services.
Is there a risk of short codes being predicted?
If sequential IDs are converted directly to Base62, the next code becomes predictable. Countermeasures include adding a random seed to the ID, applying a hash function, or generating random strings directly.

Ready to create a short URL?

Shorten a URL for Free