How Computers Work

Binary Numbers and Why Computers Use Them

Learn how base-two counting works, how to read a binary number, and why two-state switches made binary the natural choice for electronic machines.

On this page
  1. Counting With Two Symbols
  2. Reading a Binary Number
  3. Arithmetic Is Simple
  4. An Old Idea
  5. Why Two States Suit Machines
  6. Not Every Early Machine Used It
  7. Bits and Groups of Bits
  8. What to Remember

Counting With Two Symbols

People usually count in base ten, using ten digits from 0 to 9. The reason is probably anatomical, but nothing in mathematics requires it. Any whole number can be written in other bases, and base two, called binary, uses just two digits: 0 and 1.

In ordinary numbers, each position has a value ten times larger than the one to its right. In the number 352, the 2 stands for two ones, the 5 for five tens and the 3 for three hundreds. Binary works the same way, except each position is worth twice the one to its right. From the right, the place values are 1, 2, 4, 8, 16, and so on.

Reading a Binary Number

To read a binary number, add up the place values that have a 1. Take 1101. From the right, the places are 1, 2, 4 and 8. The digits are 1 (ones place), 0 (twos place), 1 (fours place) and 1 (eights place). So the value is 8 + 4 + 0 + 1 = 13.

Going the other way, to write 13 in binary, find the largest place value that fits (8), subtract it (5 left), then the fours place fits (1 left), the twos place does not, and the ones place does. That gives 1101 again.

Here are the first few numbers:

Decimal Binary
1 1
2 10
3 11
4 100
5 101
8 1000

Notice that binary numbers get long quickly. Eight is a single digit in decimal and four in binary. This is the price of using so few symbols.

Arithmetic Is Simple

The rules for adding are short. 0 + 0 = 0, 0 + 1 = 1, and 1 + 1 = 10, which means “write 0 and carry 1.” To add 5 (101) and 3 (011), work from the right: 1 + 1 gives 0 and a carry; the next column, 0 + 1 plus the carry, gives 0 and another carry; and the last column, 1 + 0 plus the carry, also gives 0 and a carry. The final carry becomes a new leading digit, leaving 1000, which is 8. That matches 5 + 3.

Because there are so few combinations, the rules can be built directly into circuits. This is the connection to logic gates, which can take on-off inputs and produce the sum and the carry.

An Old Idea

Binary notation predates electronics by centuries. Gottfried Leibniz described binary arithmetic in a paper in the early 18th century, and he was interested in its elegance. Other writers had explored similar ideas before him. In the mid-19th century, George Boole developed an algebra of logic in which statements are either true or false, which later proved to match binary closely.

The decisive bridge to machines came in the late 1930s, when Claude Shannon showed that Boolean logic could describe the behavior of switching circuits made of relays. From that point, the idea that on-off switches could carry out logical and arithmetic work was well established.

Why Two States Suit Machines

An electronic or electromechanical device is much easier to build when it only needs to tell two conditions apart. A relay is open or closed. Vacuum tubes and transistors can each be conducting or not. A spot on a magnetic surface can be magnetized in one direction or the other. In each case, a clear gap separates the two states, so small variations in voltage or temperature are unlikely to cause confusion.

If a machine had to hold ten distinct levels in a single component, for decimal digits, the margin between neighboring levels would be much smaller. Errors would be more likely, and the circuits would generally need to be more carefully built. Using two states trades more digits for much greater reliability.

This is the same reasoning that made digital designs preferable to analog computers more generally: a value that is either one state or the other tolerates noise better than a value read off a smooth scale.

Not Every Early Machine Used It

It is worth noting that binary was not adopted instantly or universally. Several machines of the 1930s and 1940s represented numbers in decimal form. ENIAC is a well-known example of an electronic machine that did its arithmetic in decimal. Some later business-oriented machines also used decimal-based codes, since commercial data is full of decimal quantities like prices.

Over time, binary became dominant in general-purpose design. Interestingly, even when a machine uses binary internally, people often prefer to see numbers in decimal, and software handles that conversion automatically.

Bits and Groups of Bits

The basic vocabulary of bits and bytes starts here: a single binary digit is called a bit. A group of eight bits is a byte, which can take 256 different values, because each of the eight places can be 0 or 1 and 2 multiplied by itself eight times is 256. Longer groups can represent larger numbers, and the same patterns can represent letters, colors, sound samples or instructions, depending on how the machine interprets them. The meaning comes from agreement about interpretation, not from the bits themselves.

Programmers often write binary values in shorter forms, such as hexadecimal (base sixteen), because long strings of 0s and 1s are hard for people to read. Each hexadecimal digit stands for four bits exactly, which makes the conversion easy.

What to Remember

Binary is not special because it is mysterious. It is a counting system with two symbols, chosen because two-state devices are dependable and cheap to build. Every stored number, picture and program in a digital computer ultimately comes down to patterns of those two states.

The complete guide to how computers work

How Computers Work: A Plain-Language Guide Through History
Read the guide

Keep exploring

Guides from other topics

All topics →