Skip to main content
Be Bitwise

What Are Bits?

Binary & Number Systems · Foundations track

5 min read

Part ofSystems Programming Companion, week 1

In this module

What Is a Bit?

At the very bottom of everything a computer does sits one almost absurdly simple idea: a bit. Short for binary digit. It can only ever be one of two values, 0 or 1.

That's it. Every photo you've taken, every message you've sent, every video you've watched. All of it built from enormous collections of zeros and ones.

Why Binary?

You might wonder why computers don't just use the decimal system you grew up with. The answer comes down to physics. Inside a computer, information rides on electrical signals, and it's straightforward to build circuits that distinguish between two states: voltage above a threshold (1) or below it (0). Try to reliably distinguish ten voltage levels (for digits 0 through 9) and you're suddenly fighting noise, drift, and manufacturing tolerances at every step.

Binary buys us reliability. Two states, less ambiguity, fewer mistakes.

Key Concept

A bit is the smallest unit of information in computing. It holds exactly one of two possible states: 0 or 1. Every piece of data a computer processes is ultimately represented as a pattern of bits.

Seeing Bits in Action

The visualiser below shows eight bits in a row. Each bit is either off (0) or on (1). Try clicking individual bits to toggle them and watch how the overall decimal value changes.

27
26
25
24
23
22
21
20
Decimal0
Hex0x00
Binary00000000

When every bit is 0, the value is zero. Turn on the rightmost bit and the value becomes 1. Flip the next bit left and you add 2. The pattern follows powers of two, each position worth twice as much as the one to its right.

How Many Patterns Fit in n Bits?

One bit gives you two patterns. Add a second bit and each of those two patterns can be followed by a 0 or a 1, so you get four: 00, 01, 10, 11. Every extra bit doubles the count again.

BitsPatternsUnsigned range
120 to 1
240 to 3
4160 to 15
82560 to 255
1665,5360 to 65,535
324,294,967,2960 to about 4.29 billion

The rule is 2^n patterns for n bits, and the largest unsigned value is always one less than that, because zero takes one of the patterns. That "one less" catches people out for years, usually at the edge of a loop.

Worked Example: Reading 00101101

Write the place value above each bit, starting from 1 on the right and doubling as you go left:

text
place: 128 64 32 16 8 4 2 1
bit: 0 0 1 0 1 1 0 1

Now add up the place values wherever the bit is 1: 32 + 8 + 4 + 1 = 45. Set those same bits in the visualiser above and it should agree with you.

Going the other way works by subtraction. To write 45 in binary, take the largest place value that fits (32), leaving 13. The largest that fits 13 is 8, leaving 5. Then 4, leaving 1. Then 1. Mark those positions with a 1 and everything else with a 0, and you're back at 00101101.

Now try it without the table. Press Clear on the visualiser below, set the bits for 45, then clear again and build 200. Work out the bits on paper first and use the decimal read-out to check yourself.

27
26
25
24
23
22
21
20
Decimal0
Hex0x00
Binary00000000
Check: which bits make 200?

11001000. The largest place value that fits 200 is 128, leaving 72. Then 64, leaving 8. Then 8, leaving nothing. That's 128 + 64 + 8.

Predict: how many bits would you need to give each of 300 students a unique ID number?

9. Eight bits only give 256 patterns, which leaves 44 students without an ID. Nine bits give 512, which is plenty. In general you need the smallest n where 2^n is at least the number of things you're labelling.

Bits Don't Know What They Mean

Here's the idea that the rest of this course keeps coming back to. The byte 01000001 is 65 if you read it as a number. Read it as text and it's the letter A. Read it as part of a machine instruction and it's something else again. Same eight bits, three meanings.

Nothing in the bits records which reading is correct. The program decides, by choosing which instruction or which type to apply. Mix those up, treating text as a number or a number as an address, and you get some of the oldest bugs in computing, plenty of which turn into security holes later in this course.

State: On or Off

In computing, we talk a lot about state, meaning the current condition of something. A single bit has exactly two possible states. Think of a light switch: on or off, nothing in between.

That on-or-off simplicity is what makes bits so powerful. Line up enough of them and you can represent anything: numbers, text, images, sound, processor instructions, the entire digital world.

Next lesson, we'll see what happens when you start grouping bits into larger units.