What is a Number Base?
A number base, also called a radix, is how many different digits a number system has before it runs out and has to start a new column. We count in base 10, most likely because we have ten fingers, so we get ten digits: 0 to 9. After 9 there is no single digit left, so we write 10, meaning one ten and no ones.
Every other base works the same way. It just runs out sooner or later. Binary (base 2) runs out after 1, so two is written 10. Hexadecimal (base 16) gets all the way to fifteen before it needs a second column. That is why the same digits can stand for different amounts: 101 is five in binary, ten in base 3, and a hundred and one in decimal. Before you convert anything, make sure you know which base it is in.
How Place Value Works
In any base, each column is worth the base times the column to its right. In decimal the columns are 1, 10, 100, and 1,000. In binary they are 1, 2, 4, 8, and 16. In hexadecimal they are 1, 16, 256, and 4,096. So 4,072 is really shorthand for:
4,072 = (4 × 1,000) + (0 × 100) + (7 × 10) + (2 × 1)
Textbooks write the columns as powers of the base, counting from 0 on the right, so 10⁰ = 1, 10¹ = 10, and 10² = 100. To make the base clear, they add it as a small number after the value, as in 101₂ for binary and 101₁₀ for decimal. The leftmost digit is the most significant digit, and the rightmost is the least significant. In binary these are called the most and least significant bits (MSB and LSB).
Bases from 2 to 36
The converter handles every base from 2 to 36. Here is the number 500 written in the ones you are most likely to come across:
| Base | Name | Digits Used | 500 in This Base |
|---|---|---|---|
| 2 | Binary | 0–1 | 111110100 |
| 3 | Ternary | 0–2 | 200112 |
| 4 | Quaternary | 0–3 | 13310 |
| 5 | Quinary | 0–4 | 4000 |
| 6 | Senary | 0–5 | 2152 |
| 7 | Septenary | 0–6 | 1313 |
| 8 | Octal | 0–7 | 764 |
| 10 | Decimal | 0–9 | 500 |
| 12 | Duodecimal | 0–9, A, B | 358 |
| 16 | Hexadecimal | 0–9, A–F | 1F4 |
| 20 | Vigesimal | 0–9, A–J | 150 |
| 32 | Base 32 | 0–9, A–V | FK |
| 36 | Base 36 | 0–9, A–Z | DW |
Some of these have a life outside computing. Base 12 lives on in dozens, inches in a foot, and the hours on a clock face, and supporters of base 12 often write ten and eleven as ↊ and ↋ instead of A and B. The Maya counted in base 20, and you can still hear it in French, where 80 is quatre-vingts, or 'four twenties'. Base 60 from ancient Mesopotamia is why an hour has 60 minutes. It needs 60 digit symbols, more than 0 to 9 and A to Z can supply.
Digit Values Above 9
Bases above 10 need more than ten digits, so they borrow letters. A is 10, B is 11, and so on up to Z, which is 35. Base 36 is the biggest base that fits into 0 to 9 plus A to Z, which is why most tools, this one included, stop there. Letters are not case-sensitive, so ff and FF are the same number.
| Letter | Value | Letter | Value | Letter | Value |
|---|---|---|---|---|---|
| A | 10 | J | 19 | S | 28 |
| B | 11 | K | 20 | T | 29 |
| C | 12 | L | 21 | U | 30 |
| D | 13 | M | 22 | V | 31 |
| E | 14 | N | 23 | W | 32 |
| F | 15 | O | 24 | X | 33 |
| G | 16 | P | 25 | Y | 34 |
| H | 17 | Q | 26 | Z | 35 |
| I | 18 | R | 27 |
How to Use the Syntax Toolbox Base Converter?
- Under 'From:', pick the base your number is written in. Binary, octal, decimal, and hexadecimal sit at the top, and the rest are under 'Extended Alphanumeric Bases'.
- Under 'To:', pick the base you want. The arrow button between the two swaps them.
- Type your number. A minus sign and a decimal point are fine, and so are spaces or underscores between digits. You can also paste values with a 0b, 0o, or 0x prefix, as long as the prefix matches the 'From' base.
Long results are easier to read with 'Group digits' switched on. Binary splits into blocks of four, hexadecimal into pairs, and decimal into thousands. The spaces are for display only, so the copy buttons always give you the plain number.
- Read the result, then look at 'Calculation steps' underneath for the full working.
- Scroll down to see the same value in binary, octal, decimal, duodecimal, hexadecimal, base 32, and base 36.
- For whole numbers, the 'Two's Complement and Bits' box shows how many bits the value needs and its bit pattern at 8, 16, 32, 64, or 128 bits.
How to Convert Between Any Two Bases
Any conversion can be done in two steps. Turn the number into decimal, then turn that decimal into the base you want. If one of the bases is already 10, you only need one of the steps.
Any Base to Decimal
Multiply each digit by its place value and add everything up. Take 2C9 in hexadecimal. C is 12, and the place values from the right are 1, 16, and 256:
2C9₁₆ = (2 × 256) + (12 × 16) + (9 × 1)
= 512 + 192 + 9 = 713
It works just as well for a base you rarely see. In base 3 the place values are 1, 3, 9, and 27:
1201₃ = (1 × 27) + (2 × 9) + (0 × 3) + (1 × 1)
= 27 + 18 + 0 + 1 = 46
As a formula, a number with digits dₙ … d₁ d₀ in base b is worth dₙ × bⁿ + … + d₁ × b¹ + d₀ × b⁰.
Decimal to Any Base
To go the other way, use repeated division. Divide by the new base and write down the remainder, then divide the quotient again. Stop when the quotient reaches 0 and read the remainders from the bottom up. Here is 713 in octal:
| Division | Quotient | Remainder |
|---|---|---|
| 713 ÷ 8 | 89 | 1 |
| 89 ÷ 8 | 11 | 1 |
| 11 ÷ 8 | 1 | 3 |
| 1 ÷ 8 | 0 | 1 |
Reading upward gives 713₁₀ = 1311₈. The first remainder you find is the last digit of the answer, and reading them in the wrong order is a common slip. A remainder of 10 or more turns into a letter, so 11 in base 16 is written B.
Between Two Bases When Neither is Decimal
Use decimal as a stopover. To turn 1201₃ into base 7, first expand it to 46 as shown above. Then divide by 7: 46 ÷ 7 = 6 remainder 4, and 6 ÷ 7 = 0 remainder 6. Reading upward, 1201₃ = 64₇. If you pick two non-decimal bases in the converter, the calculation steps show both halves one after the other.
The Shortcut for Binary, Octal, and Hexadecimal
When both bases are powers of 2, you can skip decimal altogether. One octal digit is always exactly 3 bits (2³ = 8), and one hex digit is exactly 4 bits (2⁴ = 16). Group the binary digits from the right and swap each group for a single digit:
101110101100₂
Groups of 4: 1011 1010 1100 → B A C → BAC₁₆
Groups of 3: 101 110 101 100 → 5 6 5 4 → 5654₈
If the leftmost group comes up short, pad it with zeros, so 11 becomes 0011. To get from hex to octal, write each hex digit as 4 bits and regroup in threes: 7C₁₆ is 0111 1100, which regroups as 001 111 100, or 174₈. That is why programmers use hex so much: each hex digit stands for exactly four bits, so a binary number shrinks to a quarter of its length.
Worked Examples for Common Conversions
Each of these everyday conversions uses the steps above.
Decimal to Binary
To convert 89, keep dividing by 2: 89 → 44 r1, 44 → 22 r0, 22 → 11 r0, 11 → 5 r1, 5 → 2 r1, 2 → 1 r0, and 1 → 0 r1. The remainders from the bottom up give 89₁₀ = 1011001₂.
For small numbers there is a faster way. Find the powers of 2 that add up to your number (89 = 64 + 16 + 8 + 1), then write a 1 under each of those place values and a 0 under the rest.
Binary to Decimal
Take 1110011. The place values from the left are 64, 32, 16, 8, 4, 2, and 1. Add up the ones that sit under a 1: 64 + 32 + 16 + 2 + 1 = 115.
Decimal to Hexadecimal
Start with 3,000: 3,000 ÷ 16 = 187 r8, then 187 ÷ 16 = 11 r11, then 11 ÷ 16 = 0 r11. Both 11s become B, so reading upward gives 3,000₁₀ = BB8₁₆.
Hexadecimal to Decimal
In 1F4, F is 15, so: (1 × 256) + (15 × 16) + (4 × 1) = 256 + 240 + 4 = 500.
Decimal to Octal
Dividing 493 by 8 gives 61 r5, then 61 ÷ 8 = 7 r5, then 7 ÷ 8 = 0 r7. The answer is 755₈, which may look familiar if you have ever run chmod 755 on a Linux server.
Octal to Decimal
The place values for a three-digit octal number are 64, 8, and 1, so 644 works out as (6 × 64) + (4 × 8) + (4 × 1) = 384 + 32 + 4 = 420.
Hexadecimal to Binary
Swap each hex digit for its 4 bits. For A7, A is 1010 and 7 is 0111, so A7₁₆ = 10100111₂. Binary to hex is the same thing backwards: split into fours from the right and swap each group for a digit.
Converting Fractions to Another Base
Digits after the point follow the same rule, except the place values keep shrinking. In binary they are ½, ¼, ⅛, and so on (2⁻¹, 2⁻², 2⁻³). So 0.1011₂ = 0.5 + 0 + 0.125 + 0.0625 = 0.6875.
To go from decimal to another base, split the number at the point and convert the whole part by division as usual. For the fractional part, multiply by the new base. The whole-number part of the answer is your next digit, and you carry on multiplying whatever is left:
| Multiplication | Product | Digit |
|---|---|---|
| 0.6875 × 2 | 1.375 | 1 |
| 0.375 × 2 | 0.75 | 0 |
| 0.75 × 2 | 1.5 | 1 |
| 0.5 × 2 | 1 | 1 |
This time you read the digits from the top down, so 0.6875₁₀ = 0.1011₂. Put the two halves together and 5.6875 becomes 101.1011₂.
Why Some Fractions Never End
0.1 has a single digit after the point in decimal, but in binary it is 0.000110011001100… with 0011 repeating forever. It is the same thing that happens to 1/3 in decimal. A fraction only ends in a base if every prime factor of its denominator is also a factor of the base. Ten is 2 × 5, and binary only has the 2, so most tenths can't end in binary. On the other hand, 1/3 is a tidy 0.1 in base 3.
It is also why 0.1 + 0.2 gives 0.30000000000000004 in JavaScript and plenty of other languages. The computer stores the nearest binary fraction it can fit, and the small errors show up when you add them. The converter gets around this by working with exact fractions. When a result never ends, it rounds to 20 digits after the point and shows the repeating part in brackets in the note under the result.
Negative Numbers and Two's Complement
On paper, a negative number simply keeps its minus sign, so −46 is −1201₃. The converter does the same. A computer, though, has no minus sign to store. Instead it uses two's complement inside a fixed number of bits. Here is −5 in 8 bits:
- Write 5 in 8 bits: 00000101.
- Flip every bit: 11111010.
- Add 1: 11111011, which is FB in hex.
The leading bit now works as the sign. With 8 bits you can hold −128 to 127 as signed numbers, or 0 to 255 if every bit counts toward the value. The bits themselves don't say which one you meant, and that is where a lot of bugs come from. FF is 255 to one program and −1 to another. FFFFFFFF is 4,294,967,295 as an unsigned 32-bit number and −1 as a signed one.
| Width | Unsigned Range | Signed Range |
|---|---|---|
| 8-bit | 0 to 255 | −128 to 127 |
| 16-bit | 0 to 65,535 | −32,768 to 32,767 |
| 32-bit | 0 to 4,294,967,295 | −2,147,483,648 to 2,147,483,647 |
| 64-bit | 0 to 18,446,744,073,709,551,615 | −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
Type a whole number into the converter and the 'Two's Complement and Bits' box shows its pattern at the width you choose, along with how that pattern reads as signed and unsigned. Try FFFFFFFF in base 16 at 32-bit to see both answers side by side.
Base Conversion Tables
Decimal, Binary, Octal, and Hex from 0 to 16
Binary is padded to four digits here so the columns line up. Once the 4-bit column sticks in your head, binary to hex becomes almost instant.
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 3 | 0011 | 3 | 3 |
| 4 | 0100 | 4 | 4 |
| 5 | 0101 | 5 | 5 |
| 6 | 0110 | 6 | 6 |
| 7 | 0111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
Values Worth Knowing
These come up again and again in computing. Most are either a power of 2 or one less than a power of 2. The second kind, such as 255 or 65,535, is the largest number that a set number of bits can hold.
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 100 | 1100100 | 144 | 64 |
| 127 | 1111111 | 177 | 7F |
| 128 | 10000000 | 200 | 80 |
| 255 | 11111111 | 377 | FF |
| 256 | 100000000 | 400 | 100 |
| 1,000 | 1111101000 | 1750 | 3E8 |
| 1,024 | 10000000000 | 2000 | 400 |
| 4,096 | 1000000000000 | 10000 | 1000 |
| 65,535 | 1111111111111111 | 177777 | FFFF |
| 4,294,967,295 | 11111111111111111111111111111111 | 37777777777 | FFFFFFFF |
Where Base Conversion is Used
- Schoolwork and exams: Number systems are part of most computer science courses, from school boards to university papers and exams like GATE. Questions usually ask for conversions by hand, so the calculation steps show every line of working for you to check against yours.
- Web colors: A hex color such as #1E90FF is three bytes. 1E is 30 red, 90 is 144 green, and FF is 255 blue, which makes it rgb(30, 144, 255).
- File permissions: In chmod 640, each octal digit is three bits for read, write, and execute. 6 is 110 (read and write), 4 is 100 (read only), and 0 is 000 (no access).
- Networking: An IPv4 address is four bytes written in decimal. 192.168.1.10 is 11000000.10101000.00000001.00001010 in binary. A subnet mask of 255.255.255.0 is 24 ones followed by 8 zeros, which is why it is written /24.
- Memory and debugging: Memory addresses, error codes, register values, and MAC addresses are shown in hex because two hex digits make exactly one byte.
- Text encoding: Every character has a number behind it. In Unicode, é is U+00E9, which is 233 in decimal and 11101001 in binary.
- Short IDs: Base 36 packs numbers into fewer characters and doesn't care about letter case, so it turns up in short links and reference codes. One million needs seven digits in decimal but only four in base 36.
Common Base Conversion Mistakes
- Reading remainders top to bottom: With repeated division, the first remainder is the last digit. Fraction digits are the opposite and read from the top.
- Using a digit the base doesn't have: There is no 8 or 9 in octal and no 2 in binary. The converter flags these as soon as you type them.
- Writing big remainders as two digits: A remainder of 12 in base 16 is C, not 12. Writing it as 12 adds a digit and throws off the whole answer.
- Guessing the base: 10 is ten in decimal, two in binary, and sixteen in hex. If a number arrives without a label, check where it came from first.
- Grouping bits from the wrong end: For the hex shortcut, group from the right. 11010 is 1 1010, which is 1A, not 1101 0.
- Worrying about leading zeros: 00101 and 101 are the same number. Zeros only matter in fixed-width fields such as a byte, where 0F and F0 are very different.
- Mixing up signed and unsigned: FF can mean 255 or −1. Check whether the source uses two's complement before you trust the decimal value.
Base Conversion in Excel and Google Sheets
Both programs have conversion functions built in, and they behave the same way in each:
| What You Want | Formula | Result |
|---|---|---|
| Decimal to binary | =DEC2BIN(89) | 1011001 |
| Binary to decimal | =BIN2DEC("1110011") | 115 |
| Decimal to hex | =DEC2HEX(3000) | BB8 |
| Hex to decimal | =HEX2DEC("1F4") | 500 |
| Decimal to octal | =DEC2OCT(493) | 755 |
| Decimal to any base | =BASE(713, 8) | 1311 |
| Same, padded to 8 digits | =BASE(89, 2, 8) | 01011001 |
| Any base to decimal | =DECIMAL("1201", 3) | 46 |
The older functions have tight limits. DEC2BIN only accepts −512 to 511, because it works in
10-bit two's complement, which is also why =DEC2BIN(-5) returns 1111111011 instead of −101.
DEC2OCT and DEC2HEX go further, to 30 and 40 bits. For anything else, use
BASE and DECIMAL, which cover every base from 2 to 36. BASE takes
whole numbers from 0 up to 2⁵³ and quietly drops anything after the decimal point, so fractions still need
the converter.
Base Conversion in JavaScript and Python
In code you will rarely do this by hand, since both languages have it built in. In JavaScript,
parseInt reads a number in any base from 2 to 36 and toString writes one:
// From another base to a number
parseInt('2C9', 16); // 713
parseInt('1201', 3); // 46
// From a number to another base (2 to 36)
(713).toString(8); // '1311'
(89).toString(2); // '1011001'
(3000).toString(16).toUpperCase(); // 'BB8'
// Prefixed literals
0x1F4; // 500
0b1110011; // 115
0o755; // 493
// Pad to a fixed width
(89).toString(2).padStart(8, '0'); // '01011001'
// Past 2^53, use BigInt so no digits are lost
BigInt('0xFFFFFFFFFFFFFFFF'); // 18446744073709551615n
Watch out for one thing: parseInt stops at the first character it can't read instead of
throwing an error, so parseInt('19', 8) returns 1. If the value comes from a user, validate it
first. Python's int() also reads bases 2 to 36, but it only has built-in output for binary,
octal, and hex, so other bases need a short function:
# From another base to an integer
int('2C9', 16) # 713
int('1201', 3) # 46
int('0xff', 0) # 255 (base 0 reads the prefix)
# To binary, octal, and hex
bin(89) # '0b1011001'
oct(493) # '0o755'
hex(3000) # '0xbb8'
format(89, '08b') # '01011001'
# There is no built-in for other bases, so write one
def to_base(n, base):
digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
if n == 0:
return '0'
sign = '-' if n < 0 else ''
n = abs(n)
out = ''
while n:
n, r = divmod(n, base)
out = digits[r] + out
return sign + out
to_base(713, 8) # '1311'
to_base(46, 7) # '64'
Python integers have no size limit, so both int() and the function above stay exact however
long the number gets. In JavaScript you get the same guarantee by switching to BigInt once a
value passes 2⁵³.
Sources and further reading
- Positional notation (opens in new tab) — Wikipedia
- BASE function (opens in new tab) — Microsoft
- Built-in functions: int(), bin(), oct() and hex() (opens in new tab) — Python