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.