Menu

Data Storage and Compression

Units & Conversion

Contents

  1. File Size & Storage Unit Conversion
  2. Constructing File Size Expressions
  3. Transmission Rate

Binary units of storage

Every file you save is a pattern of bits. A bit is a single binary digit, either 0 or 1, and it is the smallest unit of storage. Bits are bundled into larger units so sizes are quicker to write and read.

UnitWorth
bitone binary digit
nibble4 bits, half a byte
byte8 bits, roughly one character of text
kibibyte (KiB)1024 bytes
mebibyte (MiB)1024 KiB
gibibyte (GiB)1024 MiB
tebibyte (TiB)1024 GiB

Each unit in the table is bigger than the one before: a bit to a nibble is 4 times, a nibble to a byte is 2 times, and every step after the byte is 1024 times the one before, where 1024 is 2 to the power of 10. Counted in bytes, that gives 1 KiB = 2^10, 1 MiB = 2^20, 1 GiB = 2^30 and 1 TiB = 2^40 bytes.

Converting between units

Moving from a larger unit down to a smaller one, multiply by 1024 once for each step. Moving from a smaller unit up to a larger one, divide by 1024 once for each step. Bits and bytes work differently: multiply by 8 to turn bytes into bits, and divide by 8 to turn bits into bytes, because a byte is 8 bits.

For example, a 3 GiB game holds 3 × 1024 = 3072 MiB, which is 3072 × 1024 = 3 145 728 KiB. Going the other way, 20 480 bits is 20 480 ÷ 8 = 2560 bytes, which is 2560 ÷ 1024 = 2.5 KiB.

storage_gib = 5
print("Bytes: " + str(storage_gib * 1024 ** 3))
print("Mebibytes: " + str(storage_gib * 1024))

Output:

Bytes: 5368709120
Mebibytes: 5120

Binary and decimal prefixes

Binary prefixes — kibi-, mebi-, gibi-, tebi- — step up in 1024s. Decimal prefixes — kilo-, mega-, giga-, tera- — step up in 1000s, so 1 kilobyte is 1000 bytes and a 2 TB drive is 2 000 000 000 000 bytes. A 2 TiB drive holds noticeably more, so use whichever prefix the question gives.

Data capacity is the total storage a set of files and any extra data needs, written in a suitable unit. Convert it by multiplying or dividing by the power of 1024 that matches the units, or by 1000 for decimal prefixes.

A file size or data capacity requirement can be left as an expression: a calculation showing the quantities and conversion factors, rather than a single final value. This keeps the method visible and lets you use the units a question asks for.

Group the calculation correctly

Use brackets or a clear fraction layout so each operation applies to the right part of the expression. A short animation of 480 frames, each 786,432 bits, is (480 × 786432) / (8 × 1024^2) mebibytes. The brackets show that both the 8 and the 1024^2 divide the whole frame total, which keeps the order of operations clear. Writing 480 × 786432 / 8 × 1024^2 instead works left to right: it divides by 8 and then multiplies by 1024^2, so the answer comes out far too large.

Add extra data outside the fraction

If a requirement stores extra data on top of the main files, such as a header or an index, add it to the whole size after converting bits to bytes. A fitness tracker stores 96,000 readings at 10 bits each, plus a 2,000-byte header, so its size in bytes is:

(96000 × 10) / 8 + 2000

The header is added once, after the division by 8, because it is already counted in bytes. Writing ((96000 × 10) + 2000) / 8 would divide the header by 8 as well, so it would no longer count as 2,000 bytes.

Match the units to the factors

Use the conversion factor that matches the unit in the question. Storage uses binary multiples: a kibibyte is 1024 bytes (not 1000), a mebibyte is 1024^2 bytes, a gibibyte is 1024^3 bytes and a tebibyte is 1024^4 bytes. Decimal prefixes are different sizes, so 1024^2 belongs with mebibytes and 1000^2 with megabits. If an answer must be in kibibytes, divide the whole byte total by 1024: ((96000 × 10) / 8 + 2000) / 1024.

Transmission rate is the number of bits sent from one device to another each second. You calculate it by dividing the total number of bits by the time taken in seconds.

Getting the units right

File sizes are usually given in bytes, so multiply by 8 to change them into bits. If the time is in minutes, multiply by 60 to change it into seconds. Keep the calculation in one expression so the order is clear:

transmission rate in bits per second = (file size in bytes × 8) ÷ time in seconds

Binary storage prefixes (kibi-, mebi-, gibi- and tebi-) use powers of 1024, so a mebibyte is 1024^2 bytes. Bit-rate prefixes such as mega- are decimal: one megabit is 1000^2 bits. To give the answer in megabits per second, divide the bits per second by 1000^2.

Worked example

A 4 mebibyte game save file is uploaded to cloud storage in 20 seconds. In bits, the file is 4 × 1024^2 × 8 = 33,554,432 bits. Dividing by 20 seconds gives 1,677,721.6 bits per second. Dividing by 1000^2 gives about 1.68 megabits per second.

As one expression:

(4 × 1024^2 × 8) ÷ (20 × 1000^2) = 1.6777216 Mbps

Also useful