Skip to content

Counting the Computer's Way: Binary

In the previous section, you discovered something important: a computer, put very simply, is made of electrical circuits that only know two states. Either power is flowing, or it isn't. On or off.

But what does that mean in practice? It means that, unlike us, a computer can't "see" some random number like 7 and tell it apart from another number. For the computer there aren't ten possibilities, there are two. And it's with those two possibilities that it has to represent any number, any letter, any image, anything.

It sounds limiting, and in a way, it really is. But remember what we learned about the decimal system? The number of symbols isn't what makes a system powerful. What makes a system powerful is that trick of giving different values to different positions. That strategy works with any number of symbols, including two.

That's exactly what the binary system does: it takes two symbols and applies the positional system. The result is a system that looks strange when read by humans. But it's not humans who need to understand it - it's the computer.

You know those movies that show a programmer's or hacker's computer covered in green letters? That's where it comes from.

Zeros and ones
Zeros and ones Richard Dias Alves @ Ultimate Rust, 2025. License CC BY-NC-SA 4.0.

The Two Symbols

If the system can only have two symbols, what would they be? They could be anything: a star and a circle, the letter A and the letter B, a crab and a rodent; what matters isn't what the symbol looks like, but what it represents.

As you just saw in the image above, you can probably guess that the two symbols we adopted as the standard are 0 and 1. Remember the circuits we mentioned? The 1 represents the on state, the 0 the off state. Each symbol represents one of the two states. That simple, nothing otherworldly to interpret here.

IMPORTANT

Now comes one of the core concepts of computing, one you'll hear about for the rest of your life

Each of these symbols has a name: bit.

It's very simple to understand: just as in the decimal system the symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 are all called "digits", in the binary system the symbols are called bits. "7" is called a "digit" in the decimal system. "0" is called a "bit" in binary. "1" is also a "bit". That simple.

The symbol 0 in the binary system is not the same thing as the 0 in the decimal system, and the 1 in the binary system is also not the same thing as the 1 in decimal. They're just the same symbol; the meaning is different.

Example
  • In decimal, 10 means ten.
  • In binary, 10 means two.

Tip

Don't worry about understanding this right now; the example is just so you can see in practice what was said above. By the end of this section you'll be able to understand it.

Bit comes from binary digit. A bit is the smallest unit of information that exists in computing.

But just as a single symbol in the unary system doesn't solve much, and a single digit by itself in the decimal system doesn't represent big numbers, a single bit by itself doesn't either. On its own, it can only say two things: yes or no, on or off, 0 or 1. The magic happens when you start combining them with the positional system.

Counting in Binary

Now comes the part that looks strange at first, but will make total sense if you remember what you learned about decimal.

In decimal, you have the symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. When the symbols run out, you add a position to the left and start over (that's what the whole positional system thing means). In binary, the logic is exactly the same, except the symbols run out much sooner: after 1, that's it, and we need to start over.

Take a look at the equivalences from the binary system to decimal:

BinaryDecimal
00
11
102
113
1004
1015
1106
1117
10008

In decimal, to represent "two" there's the symbol "2" itself. In binary, by the time we get to "two" the symbols are already exhausted, so we open a new position on the left: 10.

INFO

That's not read "ten"; it's read "one, zero", and it means "one group of two, plus zero units".

  • Three in decimal is 3. In binary it's 11. It's not read "eleven"; eleven is its meaning in the decimal system. It's read "one, one" and means "one group of two, plus one unit". Two plus one: three. 10 + 1 = three (11).
  • The decimal 4 in binary is 100. You know the drill: one, zero, zero. One group of four, zero groups of two, zero units. You'll understand where that "group of four" came from in just a bit.

Tip

It takes a while for your brain to get used to reading it correctly. Your whole life, you've read in the decimal system on autopilot. Don't worry if, when you read 100, you accidentally still say "one hundred". What matters is knowing it's wrong and correcting yourself right away to one, zero, zero, until, little by little, you start saying it correctly whenever you're referring to the binary system.

The Logic of Positions

In decimal, each position is worth ten times more than the position to its right. For example: in "44", the 4 on the left is worth ten times more than the 4 on the right. That's easy enough to understand, right?

The ones position is worth 1, the tens position is worth 10, the hundreds position is worth 100, and so on. If you look closely, they're powers of 10: 10⁰, 10¹, 10², 10³...

  • 1 one = 10⁰ = 1
  • 1 ten = 10¹ = 10
  • 1 hundred = 10² = 100
  • 1 thousand = 10³ = 1000

For example, here's how the number 347 is built:

How the number 347 is formedHow the number 347 is formed
How the number 347 is formed Richard Dias Alves @ Ultimate Rust, 2025. License CC BY-NC-SA 4.0.

347 equals 3 hundreds + 4 tens + 7 ones, that is:

3 × 100  +  4 × 10   +  7 × 1
3 × 10²  +  4 × 10¹  +  7 × 10⁰

EXTREMELY IMPORTANT

This detail of the first exponent being 0 is extremely important, and you'll come to understand it later. Always remember to consider 0 the first place, not 1.

We'll come back to this in the subsection The Table the World Adopted, in the next section.

And in Binary?

In binary the same logic applies, but with 2 in place of 10. Each position is worth twice as much as the position to its right. They're powers of 2: 2⁰, 2¹, 2², 2³... Which in practice means: 1, 2, 4, 8, 16, 32, 64, 128...

So to figure out the value of any binary number, you take each bit, multiply it by the value of its position, and add it all up.

Take the binary number 1011:

1011 to 111011 to 11
1011 to 11 Richard Dias Alves @ Ultimate Rust, 2025. License CC BY-NC-SA 4.0.

The number 1011 represents eleven in decimal.

Practice time

To make sure you really got it, now try to figure out on your own the value of the following binary numbers:

Try it yourself

  1. What is 1110 in decimal?
Answer
1110 in binary1110 in binary
1110 in binary Richard Dias Alves @ Ultimate Rust, 2025. License CC BY-NC-SA 4.0.
  1. What is 10001 in decimal?
Answer
10001 in binary10001 in binary
10001 in binary Richard Dias Alves @ Ultimate Rust, 2025. License CC BY-NC-SA 4.0.

How Many Numbers Fit?

In the decimal system

  • With one digit, you can represent ten values: 0 through 9.
  • With two digits, you can represent a hundred values: 0 through 99.

Notice that the number of values you can represent is always 10ⁿ, where n is the number of digits you want to use.

In the binary system

  • With one bit, you can represent two values: 0 or 1.
  • With two bits, you can represent four values: 00, 01, 10, 11.
  • With three bits, you can represent eight values: 000 through 111.

The pattern is always the same: with n bits you can represent 2ⁿ different values.

Any group of 8 bits together is what we call a byte. A single bit can't represent much on its own, but with one byte, you can represent 256 different values (because that's 2⁸), from 0 to 255. With 4 bytes (32 bits), you can represent over four billion. With 8 bytes (64 bits), you can represent a number so large it's practically unlimited for everyday use.

For the curious

With 64 bits it's possible to represent values from 0 to 18,446,744,073,709,551,616

Eighteen quintillion, four hundred forty-six quadrillion, seven hundred forty-four trillion, seventy-three billion, seven hundred nine million, five hundred fifty-one thousand, six hundred sixteen.

It's this exponential growth that makes the binary system powerful. Every bit you add doubles the number of representable values.

Bytes, Kilobytes, and the Rest

Byte? That name sounds familiar from somewhere, doesn't it? Let's get a better grip on what these units are.

The byte is much more than a convenient number. It became the basic unit of measurement for information across all of computing. Just as we have many ways to measure distance - like centimeters, meters, kilometers... - and the meter was chosen as the base (notice that all the distance names derive from the meter), the same thing happened with the units of measurement in computing (called units of information) - the byte was chosen as the basic unit.

Going deeper

We'll dig deeper into why the byte was chosen as the basic unit in The Computer Doesn't Think in Bits, It Thinks in Bytes, in section 1.6.

And just as meters become kilometers when the numbers get too big, bytes get their own names as the quantity grows:

UnitSymbolEquivalence
Bitbsmallest unit there is
ByteB8 bits
KilobyteKB1,024 bytes (2¹⁰)
MegabyteMB1,024 KB
GigabyteGB1,024 MB
TerabyteTB1,024 GB
PetabytePB1,024 TB
To get a concrete sense

A simple text message takes up a few bytes. A song takes up a few megabytes. A movie takes up a few gigabytes.

Why This Matters for Everything

If you've made it this far, you now know something most people who use computers every day never stopped to think about: underneath it all, the computer only knows two states (which we decided to represent with two numbers, 0 and 1). Now you've understood that everything is 0s and 1s to the computer; there's no other possible state.

But maybe a reasonable question is forming in your head: how exactly does an electrical circuit "store" a 0 or a 1? If it's off, there's no power. So how does it remember anything?

The short answer is that computers use components called transistors, which work like tiny little switches - very very very tiny - inside the circuit. The circuit is made up of billions of these parts, and they're what represent the 0s and 1s while the computer is on. Wild, isn't it? Their exact inner workings are beyond our scope, and all you need to know is that behind what they do is everything you've learned up to this point.

Examples of different types of transistors
Examples of different types of transistors Daniel Ryde, Skövde, CC BY-SA 3.0, via Wikimedia Commons

But if transistors only work while the computer is on, that still doesn't answer the question how does it remember anything?. What about when the computer shuts down? How does it remember what was stored?

Going deeper

Transistors are present in practically every component of your computer:

  • In the processor, there are billions of them, responsible for doing all the calculations the computer performs.
  • In RAM, they temporarily represent (until the computer shuts down) everything the computer is using at the moment, like the program that's open and the files you're editing.
  • And so on: in the graphics card, in the audio chip, in the keyboard controller, in the motherboard's circuitry... They're everywhere!

But they all have one thing in common: they depend on power. When the computer shuts down, they lose everything.

That's what the components capable of storing information, even with the computer unplugged from the wall, are for: they're called storage devices, like HDDs and SSDs, whose inner workings you also don't need to understand to keep going with Ultimate Rust. What matters is knowing what they do: they store data. Everything you have saved - whether on your laptop, tablet, or phone - is bytes (or kilobytes, megabytes, etc...) sitting on a storage device.

Why am I learning this?

In the Rust chapters, you'll learn to create, read, and modify files directly from your program. Understanding that, deep down, everything is bits will help you understand why certain file operations work the way they do.

But think about it with me: you're reading this text right now. Letters, words, sentences, images... On a screen with formatting and colors. You just learned that the computer only understands 0s and 1s, and yet here it is, displaying all of this perfectly. How?

This is one of the most fascinating ideas in all of computing, and understanding it will change the way you see everything that shows up on your screen.

Before moving on

Can you explain why computers use the binary system instead of decimal? And can you convert a simple binary number to decimal by hand?

If so, you're ready for the next section.