S/Shortutorial
Home / Programming / Binary numbers
Programming · How computers work

Binary Numbers Explained

Everything on your computer, from photos to this page, is stored as 1s and 0s. Learn to read and write binary in a few minutes.

~8 min3 lessonsInteractive bit-flipper5-question quiz
01

Place values: tens vs twos

Our normal numbers are base 10: each place is worth 10 times the one to its right (ones, tens, hundreds…). Binary is base 2: each place is worth twice the one to its right, and the only digits are 0 and 1.

1286432168421
00101101
Example · read 00101101
  1. Add the place values wherever there's a 1
  2. 32 + 8 + 4 + 1
  3. = 45
02

Decimal to binary

Work from the biggest place value down. If it fits, write 1 and subtract; if not, write 0.

Example · 100 to binary
  1. 128 doesn't fit → 0
  2. 64 fits → 1 (36 left)
  3. 32 fits → 1 (4 left)
  4. 16 → 0, 8 → 0
  5. 4 fits → 1 (0 left)
  6. 2 → 0, 1 → 0
  7. 100 = 01100100

Counting in binary: 0, 1, 10, 11, 100, 101, 110, 111, 1000… Each time a column fills up, it rolls over, just like 9 rolling over to 10.

03

Bits, bytes and why computers use binary

A computer is built from billions of tiny switches that are either on or off, so two digits are all it needs. One binary digit is a bit; eight bits make a byte, which can store 256 different values (0–255).

UnitSizeRoughly holds
1 byte8 bitsOne letter of text
1 kilobyte (KB)1,000 bytesA short paragraph
1 megabyte (MB)1 million bytesA photo (compressed)
1 gigabyte (GB)1 billion bytesAbout an hour of HD video

Programmers often write binary in hexadecimal (base 16, digits 0–9 then A–F) because one hex digit equals four bits: 1111 1111 = FF = 255. You'll see it in colour codes like #0F7A6C.

Try it · bit-flipper

Click the bits to flip them, or type a number.

NEXTKeep learning