Flip a light switch. It is on or it is off. You can tell which state it is in without measuring anything precisely, without calibrating an instrument, and without worrying about whether the switch has drifted slightly over time. That reliability is the whole point. A transistor in a computer chip works the same way: it conducts current or it does not. Two states. Not ten, not twenty-six, just two.
Binary code is built on that physical fact. By treating one electrical state as "1" and the other as "0," engineers can represent any information they like, as long as they agree on what sequences of 1s and 0s mean. This article explains how that agreement works: what bits and bytes are, how base-2 arithmetic maps to familiar base-10 numbers, and how text, images, and sound all end up stored as strings of those digits.
What is a bit?
A bit (short for binary digit) is the smallest possible unit of digital information. It holds exactly one of two values: 0 or 1. On its own, a single bit can distinguish between two states. On or off. Yes or no. True or false. That is not much, but it is enough to build on.
In physical hardware, a bit might be represented as a high or low voltage on a wire, a magnetic domain pointing north or south on a hard drive platter, a pit or a land on an optical disc, or the charge state of a cell in flash memory. The medium changes; the two-state logic does not.
The word "bit" was coined by statistician John Tukey in 1947 and appeared in Claude Shannon's landmark 1948 paper "A Mathematical Theory of Communication," which established information theory as a field. Shannon showed that any message, regardless of its complexity, could be measured and transmitted using bits. That paper is, more or less, the theoretical foundation of everything digital.
What is a byte?
A byte is 8 bits grouped together. Why 8? It was not always the standard. Early computers used 6-bit, 7-bit, and other arrangements. The 8-bit byte became dominant during the 1960s and 1970s, partly because IBM's System/360, released in 1964, used it, and partly because 8 bits is a useful size: large enough to encode all standard ASCII characters (which need at most 7 bits), small enough to be efficient.
Eight bits can represent 256 distinct values, from 0 to 255. That range comes from the math: each bit doubles the number of possible combinations. One bit holds 2 values. Two bits hold 4. Three bits hold 8. Each additional bit doubles again. After 8 doublings starting from 1, you get 2 to the power of 8, which is 256.
File sizes are measured in bytes. A kilobyte is 1,024 bytes (or sometimes defined as exactly 1,000 bytes in storage marketing). A megabyte is roughly a million bytes; a gigabyte roughly a billion. When someone says a photo is 4 megabytes, they mean the file contains about 4 million bytes of data, which is about 32 million individual bits.
Base-2 vs. base-10: positional notation
The decimal system you use every day is base 10. Each digit position represents a power of 10, increasing from right to left. The number 305 means 3 times 100, plus 0 times 10, plus 5 times 1.
Binary works exactly the same way, but the base is 2 instead of 10. Each position represents a power of 2. The rightmost digit is 2^0 (which equals 1), the next is 2^1 (2), then 2^2 (4), then 2^3 (8), and so on, each doubling as you move left.
| Position | Power of 10 (decimal) | Power of 2 (binary) |
|---|---|---|
| Rightmost | 10^0 = 1 | 2^0 = 1 |
| Second from right | 10^1 = 10 | 2^1 = 2 |
| Third from right | 10^2 = 100 | 2^2 = 4 |
| Fourth from right | 10^3 = 1,000 | 2^3 = 8 |
| Fifth from right | 10^4 = 10,000 | 2^4 = 16 |
| Sixth from right | 10^5 = 100,000 | 2^5 = 32 |
| Seventh from right | 10^6 = 1,000,000 | 2^6 = 64 |
| Eighth from right | 10^7 = 10,000,000 | 2^7 = 128 |
To convert a binary number to decimal, identify which bit positions hold a 1, and add up the corresponding powers of 2. Positions with a 0 contribute nothing.
Worked example: 01000001 = 65 = A
Take the 8-bit binary string 01000001. Map each digit to its position value, right to left:
- Position 1 (value 1): digit 1, contributes 1
- Position 2 (value 2): digit 0, contributes 0
- Position 4 (value 4): digit 0, contributes 0
- Position 8 (value 8): digit 0, contributes 0
- Position 16 (value 16): digit 0, contributes 0
- Position 32 (value 32): digit 0, contributes 0
- Position 64 (value 64): digit 1, contributes 64
- Position 128 (value 128): digit 0, contributes 0
Total: 64 + 1 = 65.
ASCII assigns the value 65 to the uppercase letter A. So 01000001 in binary is the decimal number 65 and also the text character A, depending on how the software interprets it. That context-dependence is important: the same bits mean different things to a text decoder versus an integer math operation. The bits themselves do not carry that meaning; the software layered on top of them does.
How text, images, and sound all reduce to binary
Text is the simplest case. Each character is assigned a number (via ASCII or Unicode), and that number gets stored in binary. The text-to-binary conversion guide covers that process in detail.
Images work differently. A digital image is a grid of pixels. Each pixel has a color, and that color is described by three numbers: the intensity of red, green, and blue light, each on a scale from 0 to 255 (one byte each). A single pixel therefore takes 3 bytes, or 24 bits. A 12-megapixel photo contains 12 million pixels, each requiring 3 bytes, so the raw uncompressed data is about 36 megabytes. Image file formats like JPEG and PNG compress that data, sometimes aggressively, before writing it to disk.
Audio is a series of amplitude measurements taken many times per second. CD-quality audio samples 44,100 times per second, and each sample is a 16-bit number. Stereo audio has two channels. That works out to roughly 10 megabytes per minute before compression. MP3 and other formats compress audio by discarding sound the human ear is unlikely to notice, reducing the file size by a factor of 10 or more without audible quality loss for most listeners.
Video is images played in sequence with synchronized audio. A single second of uncompressed 1080p video at 24 frames per second is about 15 gigabytes of raw data. Modern video codecs like H.264 and H.265 reduce that to a manageable size by storing only the differences between frames, exploiting the fact that most of a video frame looks very similar to the previous one.
In every case, the underlying representation is the same: a long sequence of 0s and 1s, interpreted by software that knows what they mean.
Logic gates: where binary math gets physical
The reason binary arithmetic is useful in hardware is that simple physical components can implement binary operations directly. A logic gate is a circuit that takes one or two binary inputs and produces a binary output according to a fixed rule.
Three gates are enough to build anything:
An AND gate outputs 1 only if both inputs are 1. If either input is 0, the output is 0. Think of it as "both conditions must be true."
An OR gate outputs 1 if at least one input is 1. It outputs 0 only when both inputs are 0.
A NOT gate takes a single input and inverts it. If the input is 1, the output is 0, and vice versa.
Those three operations, combined in large numbers, implement addition, multiplication, comparison, and every other arithmetic and logical operation a processor performs. A modern CPU contains billions of transistors organized into billions of such gates. The complexity of what a processor can do does not come from sophisticated basic operations; it comes from extremely large numbers of extremely simple ones, performed at billions of cycles per second.
Why binary endures
Ternary computers (base 3) have been built. The Soviet Setun computer from 1958 used balanced ternary and performed some operations more efficiently than binary hardware of its era. Researchers have explored higher-base systems too. None displaced binary, for two related reasons.
First, two-state components are more reliable than multi-state ones at any comparable cost. Distinguishing high voltage from low is easier than distinguishing among three or more voltage levels when temperature, aging, and electrical noise all push values around.
Second, the investment in binary infrastructure is now enormous. Decades of chip design, tooling, operating systems, compilers, and software have all been built on binary. Even quantum computers, which use qubits that can be in superpositions of states, interface with conventional binary systems at their input and output.
Binary is not the only option; it is the option that turned out to be practical to build, cheap to scale, and reliable enough to stake the entire computing industry on. That is a hard combination to displace.
Things to Know
- A bit is two states, nothing more; every other unit (byte, kilobyte, megabyte) is just bits counted in bulk.
- The 8-bit byte won out in the 1960s and 1970s partly because IBM's System/360 used it and partly because 8 bits comfortably covers standard ASCII.
- Text, images, audio, and video all reduce to the same thing underneath: long runs of 0s and 1s, interpreted differently by different software.
- Three logic gates, AND, OR, and NOT, are enough to build every arithmetic and logical operation a processor performs.
Where this goes next
FAQ
Why do computers use binary instead of decimal?
Electronic circuits are reliable when they distinguish two states: a voltage is either above a threshold or below it. Representing ten distinct voltage levels precisely would require much tighter tolerances and would make circuits far more sensitive to noise and temperature variation. Two states is the simplest system that can encode information, and simpler means faster, cheaper, and more reliable at scale.
How many values can 8 bits hold?
Eight bits can hold 256 distinct values, from 0 to 255. Each bit doubles the number of possible combinations: 1 bit holds 2, 2 bits hold 4, 3 bits hold 8, and each additional bit doubles again. Eight doublings from 1 gives 2 raised to the power of 8, which is 256.
What is the difference between a bit and a byte?
A bit is the smallest unit of digital information: a single 0 or 1. A byte is a group of 8 bits. File sizes are measured in bytes (and kilobytes, megabytes, and so on). Network speeds are often measured in bits per second, which is why a 100 megabit-per-second connection downloads files at roughly 12.5 megabytes per second, not 100.
Can binary represent negative numbers?
Yes. The most common method is called two's complement. In an 8-bit two's complement system, the leftmost bit signals the sign: 0 means positive, 1 means negative. The range shifts from 0 to 255 (unsigned) to negative 128 to positive 127 (signed). This is why overflow bugs in old video games sometimes caused scores to wrap from a large positive number to a large negative one.
