Turning numbers into short codes
A shortener often assigns each link a growing numeric id. But a number like 125000000 is long. Base62 encoding rewrites that number using sixty two symbols, the digits zero to nine, lowercase a to z, and uppercase A to Z.
More symbols per character means fewer characters for the same value. Base62 packs a large id into a short string that is safe in a url and easy to read.
Why base62
- It uses only url safe characters, no symbols that need escaping.
- Sixty two symbols give huge range from few characters. Seven characters cover trillions of values.
- It is reversible. Decode the code back to the id to find the mapping.
How the size works
- Base10 uses ten symbols, base62 uses sixty two.
- Each extra character multiplies capacity by sixty two, so codes stay tiny even at scale.
- Six characters already cover over fifty billion combinations.
Key idea
Base62 encoding maps a numeric id onto sixty two url safe symbols so a large number becomes a short reversible code, with each character multiplying the range by sixty two.