Sub topic 3
Powers of two and data size units
This chapter assumes you can multiply and divide large numbers using exponents, and that you know a byte is 8 bits. It also assumes you have read the earlier chapters on why we estimate and how to round. The goal is to memorize one short table and learn when the small differences between unit systems matter.
Why powers of two
Computers address memory in binary, so sizes grow in powers of two. The useful fact is that 2^10 = 1,024, which is close to 1,000. Every 10 steps in the exponent therefore multiplies the size by about a thousand. You can do the whole estimate in powers of ten and stay within a small error.
| Power | Exact value | Approximation | Unit |
|---|---|---|---|
| 2^10 | 1,024 | 1 thousand | 1 KB |
| 2^20 | 1,048,576 | 1 million | 1 MB |
| 2^30 | 1,073,741,824 | 1 billion | 1 GB |
| 2^40 | about 1.1 trillion | 1 trillion | 1 TB |
| 2^50 | about 1.13 quadrillion | 1 quadrillion | 1 PB |
How big is the error?
The approximation drifts upward as the exponent grows. This script measures the drift.
for power, unit in ((10, "KB"), (20, "MB"), (30, "GB"), (40, "TB"), (50, "PB")):
exact = 2 ** power
approx = 10 ** (3 * power // 10)
error = (exact / approx - 1) * 100
print(f"{unit}: exact={exact:,} approx={approx:,} error={error:.1f}%")
# KB: exact=1,024 approx=1,000 error=2.4%
# MB: exact=1,048,576 approx=1,000,000 error=4.9%
# GB: exact=1,073,741,824 approx=1,000,000,000 error=7.4%
# TB: exact=1,099,511,627,776 approx=1,000,000,000,000 error=10.0%
# PB: exact=1,125,899,906,842,624 approx=1,000,000,000,000,000 error=12.6%At the terabyte scale the error is about 10%. For an estimate whose assumptions are uncertain by a factor of two or more, that is negligible. This is why the traffic and storage examples in this tutorial use decimal units, for instance 91.25 TB for five years of data.
Bytes you should remember
Estimates also need typical sizes for individual items. These are rough, and you should state them as assumptions.
- A character in ASCII text: 1 byte.
- A 64-bit integer or timestamp: 8 bytes.
- A UUID stored in binary: 16 bytes.
- A short text record with a few fields: about 500 bytes to 1 KB.
- A compressed web photo: about 200 KB to 2 MB.
- A minute of compressed video: tens of MB.
Using these, 100 million records of 500 bytes each is 100,000,000 × 500 = 50,000,000,000 bytes, or 50 GB. Counting zeros is the fastest check. Million times KB gives GB, and billion times KB gives TB.
Decimal versus binary units
Strictly, 1 GB means 10^9 bytes and 1 GiB means 2^30 bytes. Operating systems and vendors mix the two, which is why a "1 TB" drive shows less space in some tools. In a design discussion, pick decimal units, say so once, and keep them for the whole estimate. Mixing the two inside one calculation causes errors that are hard to trace.
Common mistakes
- Treating KB, MB and GB as steps of 100 or 10 instead of 1,000.
- Writing a result in the wrong unit, such as reporting 50 GB when the calculation produced 50 MB.
- Mixing bits and bytes within one estimate.
- Carrying exact values like 1,073,741,824 through the math. Round to 1 billion and move on.
Exercise
A photo service stores 2 billion photos at an average of 200 KB each. About how much storage is that? Use decimal units.
Show answer
2 billion is 2 × 10^9 and 200 KB is 2 × 10^5 bytes. The product is 4 × 10^14 bytes, which is 400 TB. Check: billion times KB gives TB, so 2 billion × 200 KB is 400 TB.