Bits and Bytes

Despite all their complexity and capability, computers understand and process information in tiny chunks consisting of bits and bytes.

Bits

A bit, short for “binary digit,” is the smallest unit of data a computer can hold. It can either be 0 or 1. Computers use binary representation because it’s well-suited for electronic implementation. Electronic components can easily distinguish between two voltage levels (high and low), which corresponds directly to the binary 0 and 1 states.

Bytes

Now, a single bit isn’t much on its own. It can only represent two states: 0 and 1. But when you start combining bits, they become more powerful. To illustrate, let’s see how many states we can represent with two bits:

Binary (the bits)Decimal (the way we humans count numbers)
0 00
0 11
1 02
1 13
We can represent four different numbers using two bits

We can extend this into groups of 8, which we call bytes. Similar to our table above, a byte can represent 256 different values (from 0 to 255), enough to cover all the letters, numbers, and common symbols we use in English. This is also why bytes because the standard: early computers were mainly developed in the US and, to a lesser extent, in the EU, so it was important to be able to represent the most important Western symbols. The table containing these symbols is called ASCII, and you can read more about it on Wikipedia. Nowadays, computers can represent all the languages of the world thanks to more advanced encodings, most notably UTF8.

Beyond Bytes

When we deal with larger pieces of data, like a photo, a song, or a movie, we use multiples of bytes:

  • Kilobyte (KB): Around 1,000 bytes.
  • Megabyte (MB): Around 1 million bytes.
  • Gigabyte (GB): Around 1 billion bytes.
  • Terabyte (TB): Around 1 trillion bytes.

Note that in the world of computers, these are usually powers of 2. So a Kilobyte is actually 1,024 bytes, a Megabyte is 1,024 Kilobytes, and so on. But for simplicity, we often round to the nearest thousand.

When you save a document on your computer, download a song, or stream a movie, you’re working with data that’s made up of millions or even billions of bytes!

Do I need to know all the details about bits and bytes?

It sure helps to know even more about this subject, but honestly, you can get very far without knowing the exact details. I want to keep this introduction light and accessible. Hence, I want to teach you the basics that we need to start programming in Python, and I won’t try to teach you how to encode a number into bits and bytes. If you’re interested, you can find many resources about this online.