Skip to main content
Binary
101010

Binary System Guide

Binary Number System

The binary system uses only two digits: 0 and 1. This is the basic language of computers, where 0 means no electricity (off) and 1 means electricity (on). Binary numbers are longer than decimal, but easier to implement in digital electronics. A byte is 8 bits (e.g., 10101010₂ = 170₁₀).

Converting to Binary

To convert decimal to binary, divide by 2 and record remainders. Example: 42 ÷ 2 = 21 remainder 0, 21 ÷ 2 = 10 remainder 1, 10 ÷ 2 = 5 remainder 0, 5 ÷ 2 = 2 remainder 1, 2 ÷ 2 = 1 remainder 0, 1 ÷ 2 = 0 remainder 1. Reading from bottom: 101010₂ = 42₁₀.

Programming Applications

Binary is used in bit masks, file permissions (e.g., chmod 755 = 111101101), IPv4 addresses, RGB colors (red #FF0000 = 11111111 00000000 00000000). RAM is addressed by bits. Boolean: true=1, false=0.

IPv6 is not four times bigger than IPv4. It is 2⁹⁶ times bigger

Bit counts are exponents, and exponents defeat intuition. An IPv6 address has four times the bits of an IPv4 address, which sounds like four times the capacity. It is actually about 79 octillion times the capacity, because every single extra bit doubles the range.

How it works

  • Converts between binary, decimal, hexadecimal and octal.
  • Shows how many distinct values a given number of bits can represent.
  • Makes the doubling explicit, which is the part that resists being guessed.
values = 2^bits

 8 bits →                256      one byte, 0–255
16 bits →             65,536      a port number
32 bits →      4,294,967,296      an IPv4 address
64 bits → 1.8 × 10¹⁹              nanosecond timestamps

one extra bit always doubles the range

Worked example

Comparing address spaces, and seeing where the familiar limits come from.

  1. IPv4 is 32 bits: 2³² = 4.29 billion addresses
  2. IPv6 is 128 bits: 2¹²⁸ ≈ 3.4 × 10³⁸
  3. the ratio is 2¹²⁸ ÷ 2³² = 2⁹⁶
  4. 2⁹⁶ ≈ 7.9 × 10²⁸ — not 4

Four times the bits is 2⁹⁶ times the addresses. The same arithmetic explains why 255 appears everywhere: eight bits give 256 values, numbered 0 to 255.

Reading the result

  • Hexadecimal exists because it is compact binary. One hex digit is exactly four bits, so two hex digits are one byte — which is why colours are written as #RRGGBB and why 0xFF is 255, or 11111111.
  • Octal is three bits per digit, which is why Unix file permissions come in threes: 755 is three groups of read, write and execute flags packed into one digit each.
  • The IPv4 exhaustion was predictable from the exponent alone. 32 bits caps the internet at 4.29 billion addresses no matter how they are allocated, and that ceiling was visible decades before it was reached.
  • Signed integers spend one bit on the sign, halving the positive range. A signed 32-bit value tops out at 2,147,483,647 rather than 4,294,967,295 — the source of a great many overflow bugs.

Common questions

Why does one byte hold 0 to 255 rather than 1 to 256?
Because counting starts at zero. Eight bits give 2⁸ = 256 distinct patterns, and the first of them represents zero, so the last represents 255. The count is 256; the maximum is 255.
Why use hex instead of binary directly?
Density without loss. Each hex digit maps to exactly four bits, so a byte is always two characters and conversion is mechanical. Writing 11111111 instead of FF is four times longer and much easier to miscount.