Skip to content
systemcoding.dev
Fundamentals

Kilobytes vs Kibibytes: KB, KiB, MB and MiB Explained

Learn why 1 KB can mean 1000 or 1024 bytes, how KiB and MiB settle it, and why a 1 TB drive shows up as 931 GiB, with a C program and numfmt examples.

6 min read
Summarize in AI
Flat illustration of two options weighed side by side, with the C, Rust and C++ logos.

A one-terabyte drive shows up in your operating system as roughly 931 gigabytes, and nobody stole the rest. The mismatch comes from two different meanings of the same prefix: a kilobyte as a thousand bytes, and a kilobyte as 1,024 bytes. The standards bodies fixed this ambiguity with separate names, kibibyte and mebibyte, but software and hardware vendors never fully agreed to use them. This post explains the two families of prefixes, who uses which, how to convert, and how GNU tools and a short C program show the difference. The command-line examples target GNU coreutils 9.5 and the C code targets GCC 14.

Two prefix families

The SI prefixes come from the metric system. Kilo means one thousand, mega means one million, giga one billion and tera one trillion, each a power of ten. They are defined by the International System of Units, and they apply to bytes the same way as to metres.

Early computing used the same words for a nearby value. Because memory is addressed with binary numbers, sizes come naturally as powers of two, and 2 to the power 10 is 1,024, close enough to 1,000 that the prefix was borrowed. A kilobyte of memory was 1,024 bytes, a megabyte 1,048,576, and so on. For a few decades the meaning was clear from context: memory used the powers of two and storage and networks used the powers of ten.

In 1998 the International Electrotechnical Commission published binary prefixes to remove the ambiguity, and they now live in ISO/IEC 80000-13. A kibibyte (KiB) is 1,024 bytes, a mebibyte (MiB) is 1,024 squared, a gibibyte (GiB) is 1,024 cubed and a tebibyte (TiB) is 1,024 to the power 4. The name is the SI prefix with the second syllable changed to bi, for binary.

PrefixSymbolValuePower
kilokB1,00010 to the power 3
megaMB1,000,00010 to the power 6
gigaGB1,000,000,00010 to the power 9
teraTB1,000,000,000,00010 to the power 12
kibiKiB1,0242 to the power 10
mebiMiB1,048,5762 to the power 20
gibiGiB1,073,741,8242 to the power 30
tebiTiB1,099,511,627,7762 to the power 40

The SI symbol for kilo is a lower-case k, so a strictly correct kilobyte is kB, while KiB has the capital K.

The gap grows with size

The difference between 1,000 and 1,024 is 2.4 percent for one step, and it compounds. Each higher prefix multiplies the gap, so at terabyte scale it is nearly ten percent. A short program makes this visible.

prefix_gap.cc
#include <stdio.h>

int main(void)
{
    const char *si[]  = { "kB", "MB", "GB", "TB" };
    const char *iec[] = { "KiB", "MiB", "GiB", "TiB" };
    unsigned long long dec = 1ULL;
    unsigned long long bin = 1ULL;

    for (int i = 0; i < 4; i++) {
        dec *= 1000ULL;
        bin *= 1024ULL;
        printf("1 %s = %llu bytes, 1 %s = %llu bytes, gap %.2f%%\n",
               si[i], dec, iec[i], bin,
               (double)(bin - dec) * 100.0 / (double)dec);
    }
    return 0;
}

The loop multiplies two running totals by 1,000 and 1,024 in step, and unsigned long long is wide enough for the terabyte values, which exceed 32 bits. The last argument is the binary prefix's excess over the decimal one, as a percentage of the decimal one.

Text
1 kB = 1000 bytes, 1 KiB = 1024 bytes, gap 2.40%
1 MB = 1000000 bytes, 1 MiB = 1048576 bytes, gap 4.86%
1 GB = 1000000000 bytes, 1 GiB = 1073741824 bytes, gap 7.37%
1 TB = 1000000000000 bytes, 1 TiB = 1099511627776 bytes, gap 9.95%

So a drive sold as one terabyte holds 1,000,000,000,000 bytes. Divide by 1,073,741,824 to express it in gibibytes, and you get about 931.32. An operating system that reports sizes in powers of 1,024 and labels them GB shows that drive as 931 GB. Both numbers describe the same number of bytes.

Who uses which

ContextConvention
Disk, SSD and USB drive capacity on the boxpowers of ten
Network speeds such as megabits per secondpowers of ten
RAM modulespowers of two, though sold as GB
CPU cache sizes and page sizespowers of two
Linux ls -h, df -h, du -hpowers of two, printed with K, M, G
Linux ls --si, df -Hpowers of ten
Windows Explorerpowers of two, labelled KB, MB, GB
macOS Finder, since 10.6powers of ten
/proc/meminfo on Linuxpowers of two, though the unit is printed as kB

The rule of thumb is that anything about address space, such as memory, caches and pages, follows powers of two because the addresses are binary, and anything sold or transmitted often follows powers of ten. A RAM stick sold as 16 GB is really 16 GiB, since the chips come in binary sizes.

GNU tools and the two systems

GNU coreutils prints human-readable sizes with -h using powers of 1,024 and -H or --si using powers of 1,000. The numfmt tool, which converts numbers to and from human-readable form, makes the contrast easy to see for a file of 1,000,000 bytes.

Shell
numfmt --to=iec 1000000
numfmt --to=iec-i 1000000
numfmt --to=si 1000000
Text
977K
977Ki
1.0M

With --to=iec, numfmt divides by 1,024 and prints the suffix as K, M or G. The iec-i form adds the i so the unit is unambiguous. The --to=si form divides by 1,000. The 976.56 result rounds up to 977 because numfmt rounds away from zero by default. Using iec-i in scripts and logs removes the guesswork, since 977Ki can only mean kibibytes.

For file listings, the same choice applies:

Shell
ls -lh archive.tar
ls -l --si archive.tar

The first prints the size with powers of 1,024 and the second with powers of 1,000. Take a file of 1,500,000 bytes. Under --si it is exactly 1.5 million bytes and prints as 1.5M. Under -h, 1,500,000 divided by 1,048,576 is about 1.43, and since ls rounds up it prints 1.5M as well. The two listings agree here by coincidence of rounding, and the prefix letters look alike in general, so the flag is what tells you which system you got.

Converting between the two by hand

You rarely need exact conversions, but you should be able to estimate. To go from a decimal figure to a binary one, divide by the ratio for that prefix: about 0.977 for kilo, 0.954 for mega, 0.931 for giga and 0.909 for tera. A 500 GB drive is about 465.7 GiB, since 500 times 0.931 is 465.7. To go the other way, multiply by 1.024, 1.049, 1.074 and 1.100.

The same arithmetic explains transfer times. A link rated at 1 gigabit per second moves 10 to the power 9 bits per second, which is 125,000,000 bytes per second, or about 119.2 MiB per second before protocol overhead. A file of 1 GiB therefore needs about 8.6 seconds on that link, and not exactly eight. When a progress bar and a stopwatch disagree by a few percent, mixed prefixes are a likely cause, and the fix is to convert both numbers to bytes first.

Writing sizes in your own code and docs

Be explicit. If a buffer is 4,096 bytes, write 4096 bytes or 4 KiB, never 4 KB. In a configuration file, a limit named max_size_kb leaves the reader guessing, while max_size_bytes does not. When you parse human input such as 64M, document whether it means mebibytes or megabytes. Most systems tools, such as dd, accept the single letter M for 1,048,576 and the two-letter MB for 1,000,000, which is the opposite of what many people assume.

Shell
dd if=/dev/zero of=blob bs=1M count=1
dd if=/dev/zero of=blob bs=1MB count=1

The first writes 1,048,576 bytes and the second writes 1,000,000. The dd manual documents the suffixes, with K, M and G as powers of 1,024 and kB, MB and GB as powers of 1,000.

Common mistakes

  • Treating 1 GB and 1 GiB as the same when sizing storage. At gigabyte scale the difference is more than seven percent.

  • Writing KB for 1,000 and also for 1,024 in the same document.

  • Dividing a drive's advertised capacity by 1,000 to predict what the operating system will show.

  • Assuming a speed in megabits per second is a speed in mebibytes per second. It differs by a factor of eight for bits against bytes, and by about five percent for the prefix.

Taggedcbeginner
Share

Keep reading

Flat illustration of user space above the system call boundary, the kernel and the hardware, with the C, FreeBSD and Linux logos.
Systems Programming

How argc and argv Reach main in a C Program

The kernel copies argc and argv onto the new process's stack on execve, then startup code hands them to main. See the layout and measure it with a program.

6 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.