Base36 represents whole numbers using all ten digits and all twenty-six letters, giving a compact, case-insensitive, alphanumeric form. It is the encoding behind many short IDs and shortened-URL schemes, where fitting a big number into a few readable characters is the goal.
How it works
Encoding repeatedly divides the number by 36 and reads the remainders from last to first; decoding does the reverse with a positional sum:
digits = 0123456789abcdefghijklmnopqrstuvwxyz
encode: while n > 0 { prepend digits[n mod 36]; n = n div 36 }
decode: value = 0; for each char c { value = value*36 + index(c) }
All arithmetic is done with arbitrary-precision integers, so the conversion is exact even for numbers with hundreds of digits.
Example and tips
The decimal number 123456789 becomes 21i3v9 in base-36 — six characters
instead of nine. Decoding 21i3v9 returns 123456789, and decoding 21I3V9
gives the same result because letters are case-insensitive. Use base-36 when you
want short human-friendly identifiers; if you need to encode raw bytes or text
rather than an integer, reach for Base32 or Base64 instead.