How Do Computers Use Binary? Calculating with 0 and 1

15 min read · Updated: October 23, 2026

A computer treats two states, high voltage and low voltage, as "1" and "0." It writes every number as a row of 0s and 1s, which is called binary. It calculates with small circuits called logic gates: you feed in 0s and 1s, and each gate gives back a fixed 0 or 1. Addition, for example, can be built from just three kinds of gates: AND, XOR and OR.

What you'll learn

  • Why computers use two values, 0 and 1, instead of ten
  • How to convert between decimal and binary (13 ↔ 1101), and what bits and bytes are
  • Circuits that add by combining gates (the half adder and the full adder)
  • How negative numbers are written (two's complement), and how subtraction and multiplication are built from addition

Prerequisites: none. It helps to know that a transistor is "a tiny switch that is flipped by electricity."

In everyday life

Type "6+7" into the calculator app on your phone, and "13" appears at once. A photo is made of millions of colored dots, and a message is made of letters. Inside the phone, all of these numbers, colors and letters are stored and processed as rows of 0s and 1s.

But if there are only 0s and 1s, how do you write 13? And how do you add 6 and 7? This article starts with how numbers are written. Then it goes step by step, all the way to the inside of a circuit that adds.

Why only two values, 0 and 1?

The core part inside a computer is a tiny switch called a transistor. A switch either lets electricity through or blocks it. In a circuit, this shows up as a voltage that is either "high" or "low." We simply agree to call these two states "1" and "0."

You might ask: why not split the voltage into ten levels and show the digits 0 to 9 directly? The problem is that the voltage in a circuit always wobbles a little. Signals in nearby wires and changes in temperature both nudge it. With ten levels, each level sits close to its neighbors, so a small wobble can cause a misread.

With only "high" and "low," there can be a wide gap between them. A small wobble almost never causes a misread. The amount of wobble a circuit can take without misreading is called the noise margin. Billions of switches must work without a single misread, so this reliability is essential. "What Is a Transistor?" explains how the switch works.

Counting in binary

The way we usually write numbers uses ten digits (0 to 9). This is called "decimal." In decimal, the places from the right are the 1s, the 10s, the 100s and so on. Each step to the left is worth 10 times more. For example, 345 means three 100s, four 10s and five 1s.

Writing numbers with only two digits, 0 and 1, is called "binary." It works the same way as decimal; only the value of each place is different. In binary, the places from the right are worth 1, 2, 4, 8, 16 and so on. Each step to the left doubles the value. Each digit is 0 or 1, so it says whether that place value is "used" or "not used."

Binary 1101 is 8 plus 4 plus 1, which is 13 Place value 8 4 2 1 Binary 1 1 0 1 Counts as 8 4 0 1 Decimal 8 + 4 + 0 + 1 = 13 Each place to the left is worth 2×
Binary 1101 is 13: add up the place values that hold a 1 (8, 4 and 1). Left out: the places above the fourth digit (16, 32, 64…).

Binary to decimal: 1101 is 13

To turn binary into decimal, just add up the place values that hold a 1. In 1101, from the left, the 8s place is 1, the 4s place is 1, the 2s place is 0 and the 1s place is 1. 8+4+1 makes 13.

Decimal to binary: 13 is 1101

To go the other way and write 13 in binary, keep dividing by 2 and write down the remainder each time.

  1. 13÷2=6 remainder 1 (1s place)
  2. 6÷2=3 remainder 0 (2s place)
  3. 3÷2=1 remainder 1 (4s place)
  4. 1÷2=0 remainder 1 (8s place)

Stop when the result of the division reaches 0. Read the remainders from the bottom up, and you get 1101. The first remainder is the 1s place and the next is the 2s place, so the digits are filled in from the right. To try other numbers, you can check your answers with the binary, hex and decimal converter.

Bits and bytes

One binary digit, a single 0 or 1, is called a "bit." The word is short for "binary digit." One bit can show only two values: 0 or 1.

Each extra bit doubles the number of patterns you can make. Two bits give four patterns: 00, 01, 10 and 11. Three bits give eight. Four bits give 16, enough to show the numbers 0 to 15.

Computers group 8 bits together and call the group "1 byte." Eight bits can form 256 patterns, which is 2 multiplied by itself 8 times. So 1 byte can hold a whole number from 0 to 255. The "GB" (gigabyte) on memory and storage is also counted in these bytes.

Adding binary numbers by hand

You add binary numbers the same way you add decimal numbers on paper: one column at a time, starting from the right. Adding two single digits has only four possible cases.

  • 0+0=0
  • 0+1=1, 1+0=1
  • 1+1=10 (binary "10" means 2: write 0 in this column and send 1 to the next column)

This is just like decimal, where 9+1 makes 10 and you send 1 to the next column. Sending 1 to the next column up is called a carry. In binary, a carry already happens at 1+1.

As an example, let's work out 6+7 with 4-digit binary numbers. To make both 4 digits long, add 0s on the left: 6 is 0110 and 7 is 0111.

8s place4s place2s place1s place
Carry from the place below110—
60110
70111
Answer1101

The 1s place is 0+1=1. The 2s place is 1+1=10, so write 0 and carry 1. The 4s place is 1+1 plus the carried 1, which is 11, so write 1 and carry 1 again. The 8s place is 0+0+1=1. The answer, 1101, is 13, as we saw earlier.

A circuit that adds: the half adder

Next, let's turn this addition into a circuit. The building blocks are "logic gates." A logic gate is a small circuit that takes 0s and 1s as input and outputs a 0 or 1 by a fixed rule. Each one is made by connecting a few to a dozen or so transistors. Here we use three kinds.

  • AND: outputs 1 only when both inputs are 1
  • OR: outputs 1 when at least one input is 1
  • XOR: outputs 1 when the two inputs are different (only one of them is 1)

Call the two single digits being added A and B, and put the four cases from earlier into a table. A table that lists every combination of inputs with the output for each is called a truth table. Each row is one combination. The last row means that 1+1 gives "carry 1, sum 0," which is 10.

ABCarrySum (the answer in this place)
0000
0101
1001
1110

The "sum" column is 1 only when A and B are different. That is exactly the XOR rule. The "carry" column is 1 only when both are 1, which is the AND rule. So one XOR gate and one AND gate side by side make a circuit that adds one digit. This circuit is called a "half adder."

Half adder: XOR gives the sum and AND gives the carry A B XOR AND Sum Carry 1 if different 1 if both are 1 e.g. 1+1 → carry 1, sum 0
A half adder simply feeds A and B into both an XOR gate and an AND gate. A dot marks where a wire branches; a crossing without a dot is not connected. Left out: the gate symbols used in real circuit diagrams, and the transistors inside each gate.

Adding the carry too: the full adder

A half adder can add one digit of two numbers. But from the second place on, you must also add the carry from the place below, as in the 4s place of 6+7. A circuit that adds three single digits (A, B and the carry from below) is called a full adder. It outputs a sum and a carry to the place above.

Another way to describe a full adder: "count how many of the three inputs are 1, and give the answer in binary." There are eight input combinations. Grouped by the number of 1s, the truth table shrinks to the four rows below.

Number of 1s in the inputsCarrySum
000
101
210
311

In the 4s place of 6+7, the inputs are 1, 1 and the carried 1: three 1s. As the last row shows, that gives carry 1 and sum 1. A full adder can be built from two half adders and one OR gate. The first half adder adds A and B. The second half adder adds that sum and the carry from below. If either half adder produces a carry, the OR gate sets the carry to the place above to 1. In the logic circuit simulator, you can load half adder and full adder examples and flip the switches to see how they work.

Line up full adders to add numbers of any length

Place one full adder for each digit, side by side. Connect each carry output to the full adder one place higher. The result is a circuit that can add numbers of any length. Four digits need four full adders; 64 digits need 64. The figure below shows this circuit working out 6+7 from earlier.

Four full adders in a row working out 0110 + 0111 6+7 (0110+0111) 0+0 1+1 1+1 0+1 8s 4s 2s 1s 0 1 1 1 1 0 1 Answer: 1101 = 13 Carries pass from right to left
Each of the four boxes is a full adder, labeled with its place (8s, 4s, 2s, 1s). The inputs for each place are at the top, the answers at the bottom, and the arrows between boxes are carries. Left out: the carry into the 1s place (0), the carry out of the 8s place (0 in this example), and the gates inside.

In this layout, the carry travels from the lower places to the higher ones like a ripple. That is why it is called a ripple-carry adder. It is simple to build. But a higher place cannot settle its answer until the carry from below arrives. With 64 digits, it may have to wait through 64 stages in the worst case.

So real CPUs use faster methods, such as working out the carries ahead of time. "Ripple-carry vs. carry-lookahead vs. carry-save adder" compares several methods in a table.

Note that a circuit has a fixed number of digits. Add 9+8 on a 4-digit circuit, and the answer, 17 (10001), needs five digits. The top 1 does not fit, so the answer becomes 0001, which is 1. This is called "overflow," and it can cause bugs in programs.

Writing negative numbers: two's complement

There are only 0s and 1s, so even the minus sign has to be written with them. Almost every computer today writes negative whole numbers with a method called two's complement. With 4 digits (4 bits), it works like this: the leftmost place is worth "−8" instead of "8."

Under this rule, 1101 is −8+4+0+1, which is −3. 0111 is +7, 1000 is −8 and 1111 is −1. Four bits can show 16 values, from −8 to +7. The same 1101 read under the rule with no negative numbers (unsigned) is 13. Which meaning it has is not set by the bits. It depends on how the program reads them.

4-bit patternRead as unsignedRead as two's complement
011177
001133
000000
111115−1
110113−3
10008−8

To flip the sign of a number, flip every 0 to 1 and every 1 to 0, then add 1. For 3 (0011), flipping gives 1100, and adding 1 gives 1101, which is −3.

The nice thing about this method is that the adding circuit from earlier works as is. Work out 5+(−3), and you get 0101+1101=10010. Just as with 9+8, the fifth-digit 1 does not fit in the 4-bit circuit. What is left is 0010, which is 2, and 5−3=2 is correct. In two's complement, dropping that 1 gives the right answer.

Subtraction and multiplication come from addition

With two's complement, subtraction becomes "adding a negative number." To work out A−B, flip the 0s and 1s of B, add 1, and add the result to A. Flipping is the job of a NOT gate, a gate that turns 0 into 1 and 1 into 0. Adding 1 is easy: set the carry into the 1s-place full adder to 1. So one adding circuit can do both addition and subtraction.

Multiplication uses an operation that moves digits sideways. In decimal, putting a 0 on the right of a number makes it 10 times bigger. In binary, moving all digits one place to the left and putting a 0 on the right doubles the number. This operation is called a "shift."

For example, 6×5 is the sum of 6×4 and 6×1, because 5 is 4+1. Shift 6 (110) two places to get 11000, which is 24. Add 110 (6) to get 11110, which is 30. Binary multiplication can be done by repeating "shift" and "add." You can watch shifts work in the bitwise operations calculator.

This explanation is simplified to show the idea. Real CPUs have a dedicated circuit that adds all the partial results of a multiplication at once. That is much faster than adding them one at a time.

Letters and colors are numbers too

For text, each character gets a number, and that number is stored in binary. This set of rules for numbering characters is called a "character code." In ASCII, a character code whose first version was set in 1963, the letter "A" is number 65. In 7 bits, that is 1000001.

Characters from other writing systems have numbers too. Unicode is a standard that gives a number to the characters of the whole world. In Unicode, the Japanese character "あ" (a) is number 12354. In UTF-8, a common format for saving text, "あ" is stored in 3 bytes.

For colors, the brightness of red, green and blue (RGB), the three primary colors of light, is each given as a number. A common format uses 8 bits per color (256 levels, 0 to 255). That gives 256×256×256 combinations, about 16.78 million colors. A photo is just these color numbers, one for each dot on the screen.

Common misconceptions

Myth: 1 means current is flowing, and 0 means no current

In fact, 0 and 1 are told apart by whether the voltage is "high" or "low," not by current. In the circuits of today's chips, almost no current flows while an output stays at 1, or while it stays at 0. Current flows mainly at the moment a signal switches between 0 and 1. The phrase "switch on and off" makes this misconception easy to pick up.

Myth: Binary needs so many digits that it must be inefficient

In fact, it is true that binary needs more digits. One million takes 7 digits in decimal but 20 in binary. Even so, the circuit for each digit is very simple and runs fast and reliably, so binary wins overall. Where storing more data matters, more than two levels are sometimes used. For example, TLC (triple-level cell) flash memory splits the voltage into 8 levels in each storage unit and stores 3 bits. The gaps between levels then get narrower. Compared with storing just 1 bit, this costs speed and the number of times the memory can be rewritten.

Myth: "1 KB" always means 1,000 bytes

In fact, there are two ways to count. The prefix kilo (k) properly means 1,000 times. But in computing, there is also a custom of counting 1,024 as 1 KB, since it is close to 1,000. (1,024 is 2 multiplied by itself 10 times.) To tell them apart, the IEC (International Electrotechnical Commission) decided in 1998 to call 1,024 bytes a "KiB" (kibibyte). Still, both are often written as "KB" today. "Memory vs Storage: What's the Difference?" explains how this affects the storage size your phone shows.

By the numbers

BitsPatternsFor comparison
1 bit20 or 1
4 bits160 to 15, or −8 to +7
8 bits (1 byte)2560 to 255
24 bits (8 bits each for RGB)about 16.78 millionthe color of one dot on a screen
32 bitsabout 4.3 billion10 digits in decimal
64 bitsabout 18.45 quintillion (18.45 × 1018)20 digits in decimal

Each extra bit doubles the number of patterns. 10 bits give 1,024 patterns, 20 bits about 1.05 million and 30 bits about 1.07 billion. A handy rule: every 10 extra bits multiply the count by about 1,000. This is also where counting "1 KB as 1,024 bytes" comes from. Most CPUs in today's PCs and phones can add two 64-bit numbers with a single instruction.

Learn more

Read next

Articles in the series “How computers work”

  1. How Do Computers Use Binary? Calculating with 0 and 1
  2. What Is a CPU? What It Does Inside Your Computer and Phone
  3. Why Are GPUs Used for AI? Matrix Math and Memory Explained
  4. What Is an Operating System? What an OS Actually Does
  5. How Does CPU Cache Work? Hit Rate, Lines and Locality
  6. What Is an NPU? The AI Engine in Phones and PCs Explained
  7. What Is an FPGA? A Chip You Can Rewire After It's Made
  8. What Is an ASIC? Custom Chips vs CPUs and FPGAs Explained
  9. How Compilers Work: From Source Code to Machine Code
  10. What Is a Logic Gate? AND, OR, NOT and How Gates Compute
  11. What Is RISC-V? The Open Instruction Set Explained
  12. What Is an Algorithm? Search, Sorting and Big-O Explained
  13. What Is a Database? Tables, SQL and Indexes Explained
  14. What Is Git? Version Control Basics and Git vs GitHub

Questions on this topic: Computer Arithmetic

Sources

All explainers