We normally count in base 10 because we have ten fingers, but computers use other bases because they fit how digital hardware works. Binary, octal and hexadecimal appear in programming, networking and web design. Once you understand place value, converting between them is straightforward.

How a Number Base Works

In any base, each position has a value equal to the base raised to a power. In decimal, the number 325 means 3 × 10^2 + 2 × 10^1 + 5 × 10^0. The same logic applies to other bases.

  • Binary (base 2) uses the digits 0 and 1. Each position is a power of 2: 1, 2, 4, 8, 16 and so on.
  • Octal (base 8) uses digits 0 to 7.
  • Hexadecimal (base 16) uses digits 0 to 9 and the letters A to F, where A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15.

Binary to Decimal

Multiply each digit by its place value and add the results. Take 101101:

  • 1 × 32 + 0 × 16 + 1 × 8 + 1 × 4 + 0 × 2 + 1 × 1 = 32 + 8 + 4 + 1 = 45.

So binary 101101 equals decimal 45. Another example: binary 1101 is 8 + 4 + 0 + 1 = 13.

Decimal to Binary

Divide the number by 2 repeatedly and record the remainders. Read them from the last remainder back to the first. For 45:

  • 45 ÷ 2 = 22 remainder 1
  • 22 ÷ 2 = 11 remainder 0
  • 11 ÷ 2 = 5 remainder 1
  • 5 ÷ 2 = 2 remainder 1
  • 2 ÷ 2 = 1 remainder 0
  • 1 ÷ 2 = 0 remainder 1

Reading the remainders from bottom to top gives 101101. The same method works for other bases: divide by 8 for octal or by 16 for hexadecimal.

Decimal to Hexadecimal and Octal

For hexadecimal, divide by 16. For 45: 45 ÷ 16 = 2 remainder 13, and 13 is D, so the result is 2D. You can check it: 2 × 16 + 13 = 45. For octal, divide by 8. For 45: 45 ÷ 8 = 5 remainder 5, so octal 55, and 5 × 8 + 5 = 45.

Why Hexadecimal Is Popular

One hexadecimal digit represents exactly four binary digits (bits), so long binary numbers become short and readable. The binary number 11111111 is FF in hex, which is 255 in decimal. Programmers use it for memory addresses, colour codes, error codes and file contents.

Reading a Hex Colour Code

Web colours often look like #FF5733. They consist of three pairs of hex digits for red, green and blue:

  • FF in hex is 255, the maximum amount of red.
  • 57 in hex is 5 × 16 + 7 = 87, a moderate amount of green.
  • 33 in hex is 3 × 16 + 3 = 51, a small amount of blue.

So #FF5733 is an orange-red with red 255, green 87 and blue 51. Each channel ranges from 0 to 255, which gives 16,777,216 possible colours.

Octal in Practice

Octal is less common, but it appears in Unix file permissions. A permission such as 755 uses three octal digits, each made of three bits that grant read (4), write (2) and execute (1). The digit 7 means 4 + 2 + 1, which is full access, and 5 means read and execute (4 + 1).

Handy Facts

  • 2^8 = 256, which is why a byte holds values from 0 to 255.
  • 2^10 = 1,024, which is why a kilobyte is often treated as 1,024 bytes in computing, though storage makers use 1,000.
  • Counting in binary on your fingers lets you reach 31 with one hand.

Common Mistakes

  • Reading the remainders in the wrong order.
  • Forgetting that hex letters A to F stand for 10 to 15.
  • Mixing up place values, which start from 2^0 on the right, not 2^1.
  • Leaving out leading zeros when a fixed width is needed, such as 8 bits for a byte.

Our guide to scientific notation covers another way of writing numbers by powers.

Your Next Step

Pick a decimal number between 1 and 255, convert it to binary and hex by hand, and check it with the Base Converter calculator. Then try reading a hex colour code from a website you like.