Base 36 converter
Convert decimal to base 36 and back, or between any two bases from 2 to 36, for whole numbers of any size. Every conversion shows its working: repeated division one way, place values the other.
A whole number of zero or more, up to 400 digits. Spaces and underscores are ignored.
Working: divide by 36, keep the remainders
| Number | ÷ 36 | Remainder | Digit |
|---|---|---|---|
| 1,000,000 | 27,777 | 28 | S |
| 27,777 | 771 | 21 | L |
| 771 | 21 | 15 | F |
| 21 | 0 | 21 | L |
Read the digits from the bottom up: LFLS. The first remainder is the last digit, because it is what is left after taking out every whole 36.
The 36 digits
Base 36 uses the ten decimal digits and then the alphabet: A is 10, Z is 35. Small and capital letters are the same digit.
Worked examples
1,000,000 to base 36
1,000,000 ÷ 36 = 27,777 r 28 → S
27,777 ÷ 36 = 771 r 21 → L
771 ÷ 36 = 21 r 15 → F
21 ÷ 36 = 0 r 21 → L
Read upwards: LFLS.
HELLO to decimal
H = 17 × 36⁴ = 28,553,472
E = 14 × 36³ = 653,184
L = 21 × 36² = 27,216
L = 21 × 36¹ = 756
O = 24 × 36⁰ = 24
Sum: 29,234,652. Any word is a base 36 number.
"Hi" as a number
The bytes 48 69 are the number 0x4869 = 18,537, which is EAX in base 36. Try it with your own text.
Powers of 36
Each place is worth 36 times the one to its right. A digit's value times its place, added up, gives the number.
| Power | Value | In base 36 |
|---|---|---|
| 36⁰ | 1 | 1 |
| 36¹ | 36 | 10 |
| 36² | 1,296 | 100 |
| 36³ | 46,656 | 1000 |
| 36⁴ | 1,679,616 | 10000 |
| 36⁵ | 60,466,176 | 100000 |
| 36⁶ | 2,176,782,336 | 1000000 |
| 36⁷ | 78,364,164,096 | 10000000 |
| 36⁸ | 2,821,109,907,456 | 100000000 |
| 36⁹ | 101,559,956,668,416 | 1000000000 |
| 36¹⁰ | 3,656,158,440,062,976 | 10000000000 |
How long a number is in base 36
A base 36 digit carries log2 36 ≈ 5.17 bits, a little more than the 5 bits of a Base32 character, so base 36 is the shortest way to write a number with digits and one case of letters. For each common width, the digits its largest unsigned value needs, and that value in base 36:
| Bits | Base 36 digits | Hex digits | Decimal digits | Largest value in base 36 |
|---|---|---|---|---|
| 8 | 2 | 2 | 3 | 73 |
| 16 | 4 | 4 | 5 | 1EKF |
| 32 | 7 | 8 | 10 | 1Z141Z3 |
| 53 | 11 | 14 | 16 | 2GOSA7PA2GV |
| 64 | 13 | 16 | 20 | 3W5E11264SGSF |
| 128 | 25 | 32 | 39 | F5LXX1ZZ5PNORYNQGLHZMSP33 |
Common mistakes
- Reading the remainders top to bottom. The first remainder is the last digit. 1,000,000 gives S, L, F, L in that order, and the answer is LFLS.
- Trusting parseInt with big numbers. JavaScript's numbers are exact only up to 253. parseInt('3w5e11264sgsf', 36) gives 18446744073709552000, which is exactly 2⁶⁴, one more than the real value, 18446744073709551615. Read long values digit by digit into a BigInt, as this converter does.
- Mixing up the letter O and the digit 0. In base 36 both are digits, O worth 24 and 0 worth nothing, and so are I (18) and 1. Where people type the codes, an alphabet that leaves the look-alikes out, such as Crockford Base32 or Base58, is safer.
- Expecting text to keep leading zero bytes. Text read as a number loses any zero bytes at the start, just as 007 is 7.
Questions
What is base 36?
A way of writing numbers with 36 digits: 0 to 9, then A to Z for 10 to 35. Each place is worth 36 times the one to its right. It is the largest base you can write with the ten digits and one case of the alphabet, which is why it is the highest base most programming languages accept.
How do I convert a number to base 36?
Divide it by 36 and write down the remainder as a digit (10 is A, 35 is Z), then divide the quotient by 36 again, until the quotient is 0. The remainders read from the last to the first are the answer. 1,000,000 gives remainders 28, 21, 15, 21, which are S, L, F, L, so it is LFLS.
How do I convert base 36 to decimal?
Multiply each digit's value by 36 to the power of its position, counting from 0 at the right, and add them up. ZZ is 35 × 36 + 35 × 1 = 1295, the largest two-digit base 36 number.
How do I convert base 36 in JavaScript or Python?
In JavaScript, n.toString(36) writes a number in base 36 (in small letters) and parseInt(s, 36) reads one back, but only exactly up to 2^53 − 1, because parseInt rounds. For bigger values, write with a BigInt's toString(36), and read by looping over the digits: total = total × 36n + BigInt(digit value). BigInt() itself does not accept base 36. In Python, int(s, 36) reads base 36 at any size, but there is no built-in to write it, so you divide by 36 in a loop as this page shows.
Is base 36 case-sensitive?
No. A and a are both 10, so HELLO and hello are the same number. That makes base 36 safe for things that ignore case, such as file names on some systems, domain names and codes read aloud. Base 62, which adds the small letters as separate digits, is shorter but case-sensitive.
How many base 36 characters does a 64-bit number need?
At most 13. The largest 64-bit value, 18,446,744,073,709,551,615, is 3W5E11264SGSF in base 36, against 16 hex digits and 20 decimal digits. A 128-bit value such as a UUID needs up to 25.
For the bases programmers use most, see the hex to decimal converter and the binary converter.