Skip to content
Back to all articles
Developer4 min readNovember 20, 2026

Binary, Octal, Decimal and Hex: How Number Base Conversion Works

Place values in plain words, step-by-step conversions with worked examples, the binary–hex shortcut, and where each base is used: colours, chmod, IP masks.

Binary, Octal, Decimal and Hex: How Number Base Conversion Works article
In this guide
  1. Place values: the one idea you need
  2. Any base to decimal: multiply and add
  3. Decimal to any base: divide and collect remainders
  4. The binary–hex shortcut
  5. Where each base is used
  6. Negative numbers
  7. Limits worth knowing

Computers work in binary, programmers write in hexadecimal, Unix permissions use octal, and people count in decimal. They are all the same numbers written in different bases. Once you understand place values, converting between them takes a minute by hand — or no time at all with the free Number Base Converter, which shows all four at once.

Place values: the one idea you need

In decimal, each position is worth ten times the one to its right: 1, 10, 100, 1000. So 347 means 3 × 100 + 4 × 10 + 7 × 1.

Every base works the same way, only the multiplier changes:

BaseDigitsPlace values (right to left)
Binary (2)0–11, 2, 4, 8, 16, 32, 64, 128 …
Octal (8)0–71, 8, 64, 512 …
Decimal (10)0–91, 10, 100, 1000 …
Hexadecimal (16)0–9, A–F1, 16, 256, 4096 …

Hexadecimal needs six extra digits, so it uses letters: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.

Any base to decimal: multiply and add

Write the place values under the digits, multiply, and add.

Binary 10011100 to decimal:

Digit10011100
Place value1286432168421

128 + 16 + 8 + 4 = 156.

Hex 9C to decimal: 9 × 16 + 12 × 1 = 144 + 12 = 156.

Octal 234 to decimal: 2 × 64 + 3 × 8 + 4 = 128 + 24 + 4 = 156.

Decimal to any base: divide and collect remainders

Divide by the base repeatedly and write down the remainders. Read them from the last to the first.

156 to binary:

DivisionResultRemainder
156 ÷ 2780
78 ÷ 2390
39 ÷ 2191
19 ÷ 291
9 ÷ 241
4 ÷ 220
2 ÷ 210
1 ÷ 201

Reading the remainders from the bottom up: 10011100.

156 to hex: 156 ÷ 16 = 9 remainder 12 (C); 9 ÷ 16 = 0 remainder 9. Bottom up: 9C.

The binary–hex shortcut

Sixteen is 2⁴, so one hex digit is exactly four binary digits. To convert binary to hex, split it into groups of four from the right and convert each group:

1001 1100
   9    C   →  9C

Going the other way, expand each hex digit to four bits: F = 1111, A = 1010, so FA = 11111010. This is why hex is used to write bytes: one byte (8 bits) is always exactly two hex digits, from 00 to FF.

Octal works the same way with groups of three bits, because 8 is 2³.

Where each base is used

Hex colour codes. #1E90FF is three bytes: 1E = 30 red, 90 = 144 green, FF = 255 blue. Convert colours between formats with the Color Converter.

Unix file permissions. In chmod 755, each octal digit is three bits — read (4), write (2), execute (1):

DigitBitsMeaning
7111read, write, execute (owner)
5101read, execute (group)
5101read, execute (others)

chmod 644 (110 100 100) is read-write for the owner and read-only for everyone else.

IP subnet masks. 255.255.255.0 is 11111111.11111111.11111111.00000000 — twenty-four 1-bits, written /24.

Bit flags. If a setting value is 12, binary 1100 tells you flags 3 and 4 (values 8 and 4) are on.

Memory addresses, error codes and file signatures are almost always shown in hex. A PDF file starts with the bytes 25 50 44 46 — “%PDF” in ASCII.

Negative numbers

On paper, negative numbers just get a minus sign: −10 is −1010 in binary. Inside computers, signed integers use two's complement: to negate, flip every bit and add 1. In 8 bits, 10 is 00001010, so −10 is 11110110, and −1 is 11111111 (FF). The Number Base Converter shows the minus-sign form; two's complement depends on the bit width you are working with.

Limits worth knowing

  • Fractions can be converted too (multiply the fractional part by the base repeatedly), but many simple decimal fractions, like 0.1, never end in binary — which is why 0.1 + 0.2 is not exactly 0.3 in most programming languages.
  • Very large numbers lose precision in JavaScript beyond 2⁵³ − 1 (9,007,199,254,740,991). Use BigInt for larger values.
  • Prefixes in code: 0b1010 (binary), 0o12 (octal), 0xA (hex) — all equal 10.

Check any of the examples above in the Number Base Converter: pick the base you are typing in, and all four appear as you type.

Was this article helpful?

Found this guide useful?

Share it with someone who is struggling with the same problem.

Free tool · No sign-up

Number Base Converter

Convert numbers between binary, octal, decimal and hexadecimal. Type in any base and see all four at once, each with its own copy button.

Open tool

Written by

Hemant Adhikari HemantInsights

Senior Software Engineer · Developer of Toolyconvert

I’m a senior software engineer from Dehradun, India, building websites since 2014. I designed and developed Toolyconvert, from the Next.js front end and headless WordPress back end to the tools themselves, and I review every guide before it goes live.