A computer can only distinguish two states
Inside the processor there are billions of transistors. Each one works like a switch: it lets current through or it does not. We call that smallest state, 0 or 1, a bit (binary digit).
Why two states and not ten
A real signal has noise, but that does not matter: everything above the threshold is a 1 and everything below it is a 0. With two states that are far apart, the computer almost never makes a mistake. With ten voltage levels, a little noise could turn a 6 into a 7.
With n bits, how many combinations are there?
Every bit you add doubles the number of combinations. With 8 bits (one byte) there are 256: numbers from 0 to 255.
Switch on bulbs and make a number click on each bulb
One quantity, four ways to write it
A number system is a set of symbols and some rules for combining them. In positional systems, the value of each digit depends on where it is. The base tells you how many symbols there are and how much each step in position is worth.
Binary · base 2
The language of hardware. Weights: 1, 2, 4, 8, 16…
Octal · base 8
A shorthand for binary, 3 bits at a time. It is used in Linux permissions.
Decimal · base 10
The one we use, because we have ten fingers. Weights: 1, 10, 100…
Hexadecimal · base 16
A shorthand for binary, 4 bits at a time. When we run out of digits, we continue with letters: A=10 … F=15.
The odometer what happens when we run out of symbols?
Break a number down by position
General rule, the fundamental theorem of numeration: each digit is multiplied by the base raised to its position (starting at 0 on the right), and everything is added up. The little squares show how many times the weight of each column is repeated.
Three methods that cover every case
From any base to decimal: add up the weights (tab 2). From decimal to another base: repeated division. Between binary, octal and hexadecimal: group the bits, without going through decimal.
Decimal → another base: repeated division
Binary ↔ octal and hexadecimal: grouping
The pale zeros are padding: they are added on the left to complete the last group and do not change the value. To go the other way, replace each octal digit with its 3 bits or each hexadecimal digit with its 4 bits.
Reference table 0–15 worth learning by heart
Everything ends up as bits
The computer stores everything in binary: text, colours, network addresses, permissions. We use hexadecimal and octal because they are short ways of writing that binary.
Screen colours web, design, CSS
Each channel is 1 byte (0–255). A byte is 8 bits and is written with exactly 2 hexadecimal digits. That is why web colours have 6 digits: 3 bytes, 24 bits, 16,777,216 colours.
Text is numbers too ASCII and UTF-8
Every character has a code. Basic letters take up 1 byte (ASCII). Characters such as ñ, á or an emoji take up 2, 3 or 4 bytes in UTF-8: they appear with a dashed border.
IP addresses networks, an SMR module
An IPv4 address is 32 bits divided into 4 octets of 8 bits. Each number goes from 0 to 255 because it is one byte. Subnet masks (255.255.255.0) can only be understood properly in binary.
Linux permissions chmod uses octal
Each group of permissions is 3 bits (read=4, write=2, execute=1), which is exactly what fits in one octal digit. chmod 755 means 111 101 101.
Other places where you will see hexadecimal
| Where | Example | What it is |
|---|---|---|
| MAC address | 3C:52:82:1A:F0:9B | 6 bytes that identify a network card |
| IPv6 | 2001:0db8:85a3::8a2e:0370:7334 | 128 bits written in blocks of 4 hex digits |
| Memory addresses | 0x7FFE4A10 | The prefix 0x means hexadecimal |
| Windows blue screen | 0x0000007B | System error code |
| Hex editors | 89 50 4E 47 | First bytes of any PNG file |
From the bit to the terabyte
The bit (lowercase b) is the smallest unit. The byte (uppercase B) is 8 bits and is the unit used to measure storage. From there we use prefixes: kilo, mega, giga, tera…
The ladder of units
Here we use the International System of Units (SI): each step is ×1000. In tab 6 we will see why ×1024 is sometimes used.
bit or Byte: watch the capital letter
Network speeds are measured in bits per second (Mbps, Mb/s). Files are measured in bytes (MB). That is why a "600 Mbps" fibre connection does not download at 600 MB per second.
How much space does each thing take? logarithmic scale: each mark is ×1000
If we drew this on a normal scale, the letter would be invisible next to the hard drive: a 1 TB drive is 10¹² times (a million million times) bigger than one letter. That is why each vertical line multiplies by 1000.
Unit converter
Why does my 1 TB drive only have 931 GB?
Because "kilo" has been used with two different meanings. In the International System, kilo = 1000. But computers work with powers of 2, and 2¹⁰ = 1024 is very close to 1000, so for decades 1024 bytes were called a "kilobyte".
Simulator: buy a drive
The error grows with every prefix
With kilo the difference is only 2.4%, and nobody worried. With terabyte drives it is already almost 10%, enough to cause complaints and even lawsuits against manufacturers.
The two families of prefixes
| Decimal (SI) | Value | Binary (IEC) | Value | Difference |
|---|---|---|---|---|
| kB kilobyte | 10³ = 1,000 | KiB kibibyte | 2¹⁰ = 1,024 | 2.4% |
| MB megabyte | 10⁶ = 1,000,000 | MiB mebibyte | 2²⁰ = 1,048,576 | 4.9% |
| GB gigabyte | 10⁹ | GiB gibibyte | 2³⁰ = 1,073,741,824 | 7.4% |
| TB terabyte | 10¹² | TiB tebibyte | 2⁴⁰ | 10.0% |
| PB petabyte | 10¹⁵ | PiB pebibyte | 2⁵⁰ | 12.6% |
The "bi" in kibi, mebi, gibi comes from binary: kilo-binary, mega-binary, giga-binary. It is written with an i in the middle: KiB, MiB, GiB.
How this mix-up came about
Memory chips are built in powers of 2. As 1024 ≈ 1000, computer people say "kilo" for convenience.
With megas and gigas the approximation gets worse. Some manufacturers use ×1000 and others ×1024. A "1.44 MB" floppy disk mixed both: 1.44 × 1000 × 1024 bytes.
The IEC (International Electrotechnical Commission) creates the binary prefixes: kibi, mebi, gibi. Kilo goes back to meaning only 1000.
The ISO/IEC 80000-13 standard includes them. It is the standardised, correct form.
Both habits exist side by side. You need to know which one each program uses.
Who uses what?
| Where | Divides by | Label |
|---|---|---|
| Manufacturers of hard drives, SSDs and USB sticks | 1000 | GB, TB (correct) |
| Windows (File Explorer) | 1024 | GB (should be GiB) |
| macOS since 2009 | 1000 | GB (correct) |
| Linux (depends on the tool) | 1024 | GiB, or just G |
| RAM | 1024 | "16 GB" that are really 16 GiB |
| Network speeds | 1000 | Mbps (bits) |
A trick to remember it: if it has an i, it is a power of 2. If it has no i, in theory it is a power of 10, even though Windows does not follow this.
Random exercises
Choose a type of exercise, solve it on paper and check your answer. If you get it wrong, you can see the solution step by step.