Base62 Encoding Fundamentals
What you'll learn: Why Base62 is the standard choice for URL shorteners and how it packs maximum information into minimal characters.
The Character Set Advantage
Base62 encoding uses exactly 62 characters: uppercase letters (A-Z), lowercase letters (a-z), and digits (0-9). This gives you 26 + 26 + 10 = 62 possible values per character position.
Why does this matter for URL shorteners? More characters per position means exponentially more unique URLs with fewer characters.
The Math Behind the Magic
With Base62, a 7-character short code can represent:
62^7 = 3,521,614,606,832 unique URLs (over 3.5 trillion)
Compare this to Base10 (digits only):
10^7 = 10,000,000 unique URLs (only 10 million)
You'd need 11 digits in Base10 to match what Base62 does in just 7 characters.
Why Not Base64?
You might wonder about Base64, which includes + and /. The problem? Those characters require URL encoding (%2B and %2F), defeating the purpose of short URLs. Base62 stays URL-safe without encoding.
The Encoding Process
Think of Base62 like counting, but instead of rolling over at 9 (decimal), you count through all 62 characters:
0, 1, 2...9, A, B, C...Z, a, b, c...z- After
z, you increment the next position:10(in Base62)
Each unique ID maps to exactly one Base62 string, ensuring collision-free short URLs when combined with proper ID generation.
Key Takeaway: Base62 maximizes the namespace within short, URL-safe strings—perfect for creating billions of unique short links with just 6-7 characters, balancing human readability with technical efficiency.