Binary Representation & Number Systems (Essential)
Bits and Bytes
Read aloud is unavailable in this browser.
The Atoms of Digital Information
Every piece of digital information you've ever encountered — every text message, every photograph, every video stream, every program, every database record — is ultimately composed of the same fundamental unit: the bit.
Bits are to computing what atoms are to chemistry. Just as all matter is composed of atoms, all digital information is composed of bits. Understanding bits and their organized groupings (bytes, words, etc.) is essential for understanding how computers represent, store, and process anything and everything.
In the previous page, we learned why computers use binary. Now we'll explore how binary data is structured — the units we use to measure it, organize it, and reason about it. This knowledge is foundational for understanding memory, storage, data types, and algorithm complexity.
By the end of this page, you will understand bits, bytes, and their larger groupings intimately. You'll know exactly how much data each unit can represent, how they relate to memory and storage, and why certain numbers like 8, 256, and 4,294,967,296 appear constantly in computing.
What Is a Bit?
A bit (short for binary digit) is the smallest unit of data in computing. It represents a single binary value: either 0 or 1.
The Dual Nature of a Bit:
A bit is simultaneously a physical entity and an abstract concept:
Physically, a bit is:
- A voltage level in a circuit (high ≈ 1, low ≈ 0)
- A magnetic orientation on a hard drive (north ≈ 1, south ≈ 0)
- A charge level in flash memory (charged ≈ 1, uncharged ≈ 0)
- A light pulse in fiber optics (light ≈ 1, no light ≈ 0)
Abstractly, a bit is:
- The answer to any yes/no question
- The distinction between two possible states
- The minimum unit of information
Information Theory Perspective:
In Claude Shannon's information theory, a bit is formally defined as the amount of information required to distinguish between two equally probable outcomes. If you flip a fair coin, you need exactly 1 bit of information to record whether it landed heads or tails.
The word 'bit' was coined by John Tukey at Bell Labs in 1947, as a contraction of 'binary digit.' It's one of the most successful neologisms in the history of science — a word that went from invention to universal adoption within a decade.
What Can a Single Bit Represent?
With just one bit, you can represent any distinction between two states:
| Domain | State 0 | State 1 |
|---|---|---|
| Logic | False | True |
| Electronics | Off | On |
| Gender (binary) | Male | Female |
| Outcome | Failure | Success |
| Direction | Left | Right |
| Polarity | Negative | Positive |
| Presence | Absent | Present |
| Access | Denied | Granted |
The power of bits isn't in what a single bit can represent — it's in how multiple bits combine to represent exponentially more states.
The Power of Multiple Bits
Here's the fundamental mathematical truth that makes digital computing possible: n bits can represent 2ⁿ distinct values.
This exponential relationship is crucial. Let's trace it:
| Bits | Formula | Distinct Values | Practical Example |
|---|---|---|---|
| 1 | 2¹ | 2 | On/Off, True/False |
| 2 | 2² | 4 | Four directions: N, E, S, W |
| 3 | 2³ | 8 | Eight colors, days of week + 1 |
| 4 | 2⁴ | 16 | Hexadecimal digit (0-F) |
| 5 | 2⁵ | 32 | 26 letters + 6 symbols |
| 6 | 2⁶ | 64 | Base64 encoding character set |
| 7 | 2⁷ | 128 | ASCII character set |
| 8 | 2⁸ | 256 | Extended ASCII, single byte |
| 16 | 2¹⁶ | 65,536 | Unicode Basic Multilingual Plane |
| 32 | 2³² | 4,294,967,296 | IPv4 addresses, 32-bit integers |
| 64 | 2⁶⁴ | 18,446,744,073,709,551,616 | Modern memory addresses, 64-bit integers |
The Exponential Explosion:
Notice how quickly the numbers grow. Adding just one bit doubles the range. This is why computers can represent virtually anything with enough bits:
- 10 bits: 1,024 values (≈ 1 thousand)
- 20 bits: 1,048,576 values (≈ 1 million)
- 30 bits: 1,073,741,824 values (≈ 1 billion)
- 40 bits: 1,099,511,627,776 values (≈ 1 trillion)
This exponential growth is the fundamental reason digital systems can represent complex information — from simple counters to high-definition video — using the same simple building block: the bit.
As you study computer science, you'll encounter powers of 2 constantly: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024... Learn to recognize them instantly. They appear in memory sizes, data structure capacities, hash table sizes, protocol limits, and countless other contexts. They're the natural numbers of computing.
What Is a Byte?
A byte is a group of 8 bits. It is the fundamental unit of data storage and addressing in virtually all modern computers.
Why 8 Bits?
The 8-bit byte wasn't always standard. Early computers used various word sizes: 6-bit, 7-bit, 12-bit, and others. The 8-bit byte became dominant for several reasons:
-
Character Encoding: 7 bits (128 values) were enough for ASCII characters, and 8 bits (256 values) allowed for extended character sets.
-
Power of Two: 8 is a power of 2, making byte arithmetic simple and efficient.
-
Hardware Convenience: 8 bits fit neatly on circuit boards and memory chips.
-
IBM's Influence: The IBM System/360 (1964) standardized the 8-bit byte, and its immense commercial success made this the de facto standard.
What a Byte Can Represent:
With 8 bits, a byte can represent 256 (2⁸) distinct values, typically used as:
- •An unsigned integer from 0 to 255 — The natural range of a byte
- •A signed integer from -128 to 127 — Using two's complement representation
- •A character — In ASCII or Latin-1 encoding
- •A grayscale pixel value — From black (0) to white (255)
- •One color channel — The R, G, or B component of a pixel
- •A boolean with metadata — True/False plus 7 bits of extra information
- •Eight boolean flags — Each bit storing a separate yes/no value
Historically, 'byte' didn't always mean exactly 8 bits. In some systems, bytes were 6 or 7 bits. The term 'octet' is used in networking and telecommunications to unambiguously mean exactly 8 bits. In modern practice, 'byte' and 'octet' are synonymous, but you may encounter 'octet' in network protocol specifications.
Larger Units: Kilobytes, Megabytes, and Beyond
As data needs grew, we needed terms for larger quantities of bytes. This led to the familiar kilobyte, megabyte, gigabyte, and so on. However, there's a confusing historical inconsistency here that every engineer should understand.
The Binary vs. Decimal Confusion:
In everyday usage, "kilo" means 1,000, "mega" means 1,000,000, and so forth (powers of 10). But in computing, memory and storage have traditionally been sized in powers of 2.
This created the awkward situation where:
- 1 kiloByte was sometimes 1,000 bytes (10³)
- 1 kiloByte was sometimes 1,024 bytes (2¹⁰)
| Name | Binary (IEC) | Decimal (SI) | Difference |
|---|---|---|---|
| Kilo | 1,024 bytes (2¹⁰) = 1 KiB | 1,000 bytes (10³) = 1 KB | 2.4% |
| Mega | 1,048,576 bytes (2²⁰) = 1 MiB | 1,000,000 bytes (10⁶) = 1 MB | 4.9% |
| Giga | 1,073,741,824 bytes (2³⁰) = 1 GiB | 1,000,000,000 bytes (10⁹) = 1 GB | 7.4% |
| Tera | 1,099,511,627,776 bytes (2⁴⁰) = 1 TiB | 1,000,000,000,000 bytes (10¹²) = 1 TB | 10.0% |
| Peta | 1,125,899,906,842,624 bytes (2⁵⁰) = 1 PiB | 10¹⁵ bytes = 1 PB | 12.6% |
The IEC Standard:
To resolve this ambiguity, the International Electrotechnical Commission (IEC) introduced new prefixes:
- Ki (kibi) = 2¹⁰ = 1,024
- Mi (mebi) = 2²⁰ = 1,048,576
- Gi (gibi) = 2³⁰ = 1,073,741,824
So 1 MiB (mebibyte) is exactly 2²⁰ bytes, while 1 MB (megabyte) is exactly 10⁶ bytes.
Practical Reality:
In practice, the situation is messy:
- RAM is always measured in binary units (your "8 GB" RAM is really 8 GiB)
- Hard drives and SSDs use decimal units (a "1 TB" drive is exactly 10¹² bytes)
- File sizes are typically shown in binary units by operating systems
This is why a "1 TB" hard drive shows up as "931 GB" in your operating system — the drive uses decimal (1,000,000,000,000 bytes), but the OS displays binary (÷ 1,073,741,824).
In casual conversation, the difference rarely matters. But when calculating buffer sizes, network capacities, or storage requirements, the ~10% difference at the gigabyte level can be significant. Use GiB/MiB when you mean binary units, and GB/MB when you mean decimal units. Your future self (and colleagues) will thank you.
Words, Addresses, and Architecture
While bytes are the fundamental addressable unit, CPUs typically work with larger chunks called words.
What Is a Word?
A word is the natural data size for a particular processor architecture. It's the amount of data a CPU can process in a single operation and typically matches the width of its registers.
- 32-bit architecture: Word = 32 bits = 4 bytes
- 64-bit architecture: Word = 64 bits = 8 bytes
The word size affects many aspects of computing:
- •Memory Addressing: A 32-bit system can address 2³² = 4 GB of RAM directly. A 64-bit system can address 2⁶⁴ = 16 exabytes (though practical limits are lower).
- •Integer Range: Native integers match word size. A 32-bit int ranges from -2³¹ to 2³¹-1 (~±2 billion).
- •Performance: Operations on word-sized data are fastest. Smaller data may require masking; larger data requires multiple operations.
- •Pointer Size: Pointers (memory addresses) are word-sized. This determines how much memory a single pointer can reference.
Memory Addressing:
Every byte in memory has a unique address — a number that identifies its location. When you access memory, you specify the address, and the hardware retrieves the byte(s) at that location.
Conceptual Model of Memory:
Address Data (Byte)
0x00000000 [01001101]
0x00000001 [11100010]
0x00000002 [00000000]
0x00000003 [11111111]
0x00000004 [10101010]
... ...
In a 64-bit system, addresses are 64 bits long, allowing for an astronomical number of possible addresses. However, practical systems use only a fraction of this address space due to physical memory limits and operating system constraints.
The shift from 32-bit to 64-bit computing wasn't just about speed — it was about addressing. With 32 bits, a program can address at most 4 GB of RAM, which became limiting as applications grew larger. 64-bit addressing removes this constraint entirely — 16 exabytes is more than any foreseeable application needs.
Bit and Byte Ordering: Endianness
When a multi-byte value (like a 32-bit integer) is stored in memory, the individual bytes must be placed in some order. Endianness describes this ordering.
Little-Endian:
The least significant byte (the "small end") is stored at the lowest memory address.
Example: The 32-bit integer 0x12345678 stored at address 0x100:
0x100: 78 (least significant)
0x101: 56
0x102: 34
0x103: 12 (most significant)
Big-Endian:
The most significant byte (the "big end") is stored at the lowest memory address.
Example: The same integer stored big-endian:
0x100: 12 (most significant)
0x101: 34
0x102: 56
0x103: 78 (least significant)
| Architecture/Protocol | Endianness | Notes |
|---|---|---|
| x86, x64 (Intel/AMD) | Little-Endian | Most PCs and servers |
| ARM (configurable) | Little-Endian (default) | Most phones, tablets, Macs with Apple Silicon |
| Network protocols (IP, TCP) | Big-Endian | Called 'network byte order' |
| PowerPC (older) | Big-Endian | Older Macs, some game consoles |
| SPARC (older) | Big-Endian | Sun workstations |
Why Does This Matter?
Endianness rarely matters when working within a single system — the same CPU that writes data will read it back correctly. It becomes critical when:
-
Network Communication: Data sent between different machines must agree on byte order. That's why network protocols standardize on big-endian ("network byte order").
-
File Formats: Binary file formats must specify endianness, or files become unreadable on different architectures.
-
Cross-Platform Development: Code that manipulates bytes directly (like parsers or serializers) must handle endianness explicitly.
-
Debugging: When examining raw memory, you need to know the endianness to interpret multi-byte values correctly.
The terms 'big-endian' and 'little-endian' come from Jonathan Swift's Gulliver's Travels, where the Lilliputians fought a war over which end of an egg to crack first. Danny Cohen used the terms in a 1980 paper 'On Holy Wars and a Plea for Peace,' highlighting the arbitrary nature of the choice.
Units of Data Transfer: Bits per Second
While storage is measured in bytes, data transfer rates are typically measured in bits per second. This is an important distinction that often confuses beginners.
Why Bits for Transfer?
Historically, communication lines transmitted data serially — one bit at a time. Thus, "bits per second" (bps) became the natural unit for measuring transfer speed. This convention persists today.
Common Speed Units:
- bps = bits per second
- Kbps = kilobits per second = 1,000 bps
- Mbps = megabits per second = 1,000,000 bps
- Gbps = gigabits per second = 1,000,000,000 bps
Note: These use decimal prefixes (powers of 10), unlike storage which uses binary.
| Connection Speed | Bytes per Second | Time to Download 1 GB |
|---|---|---|
| 10 Mbps | 1.25 MB/s | ~13 minutes |
| 100 Mbps | 12.5 MB/s | ~80 seconds |
| 1 Gbps | 125 MB/s | ~8 seconds |
| 10 Gbps | 1.25 GB/s | ~0.8 seconds |
The Bits-to-Bytes Trap:
When an ISP advertises "100 Mbps internet," they mean 100 megabits per second. To convert to megabytes per second (more useful for thinking about file downloads), divide by 8:
100 Mbps ÷ 8 = 12.5 MBps
This is why downloads feel slower than the advertised speed suggests — looking at bits instead of bytes makes the number appear 8 times larger.
ISPs advertise in bits per second because bigger numbers look better in marketing. Storage manufacturers use decimal bytes for the same reason. Always verify which unit is being used and convert to a consistent system when comparing specifications.
KEEP LEARNING
There’s more to understand.
You’re reading the introduction. Create a free account to read the complete lesson, save notes and keep track of your progress.