I have noticed that different applications use different units, or mean different things by them.
For example, I have come across kB
, KB
, KiB
, Kb
and K
. How many bytes do each of these units represent?
If there are different definitions for these units, which ones do which applications use?
Introduction:
Data in electronic computers is stored and transmitted in various ways, but they are always interpreted as a sequence of binary values, either 0 or 1. One binary value is called a bit. Eight bits is called an octet, or a byte. On this there is consensus.
A bit is denoted as
b
, and a byte asB
. On this there is consensus, and if you ever spot an application breaking this convention, it's definitely a bug or an error. People frequently confuse the two, but application developers and manufacturers on the whole do not.Once you get to larger units, there are two schools of thought, which sadly means that there is no consensus. Different operating systems and different applications belong to one school of thought or another.
Ubuntu's unit policy:
Ubuntu has a published units policy, which defines units like this.
The first set of units are multiples of 1024. (Why 1024? Because 1024 is 2 to the power of 10, which can make life easier for programmers.) This set of units is called binary units or the IEC prefixes, after the IEC standard that defined them:
1KiB
= 1024 bytes (note the capital K)1MiB
=1024KiB
= 1048576 bytes1GiB
=1024MiB
=1048576KiB
= 1073741824 bytesThe second set of units are multiples of 1000. This aligns much more closely with commonly used units in the SI system, such as metres, litres and grams. A kilogram is 1000 grams; in the same way, a kilobyte is 1000 bytes. This set of units is called decimal units or the SI prefixes.
1kB
= 1000 bytes (note the lowercase k)1MB
=1000kB
= 1000000 bytes1GB
=1000MB
=1000000kB
= 1000000000 bytesThe traditional units:
Traditionally, many applications, operating systems and developers used binary units, giving them SI names. Ubuntu, GNOME and OS X all attempt to follow the published standards as explained previously, however, Microsoft Windows and many UNIX utilities still use these traditional units, so you need to be aware of them.
1KB
= 1024 bytes (note the capital K)1MB
=1024KB
= 1048576 bytes1GB
=1024MB
=1048576KB
= 1073741824 bytesTraditionally, however, speeds are specified in bits per second, with SI prefixes! So 1Mbps is actually 1000000 bits per second, which is 125000 bytes per second, even on Microsoft Windows.
How to avoid ambiguity:
As you can see, these conflicting definitions lead to a lot of confusion. When I say
1MB
, do I mean a million bytes, or do I mean 1048576 bytes?To avoid ambiguity, you should use one of these strategies:
1MiB
is always unambiguous.Where there is ambiguity, here's a good set of rules of thumb that has served me well:
KB
(with a capital K), then the traditional units are probably being used.kB
(with a lowercase k), then the SI units are probably being used.When it comes to Ubuntu applications, have a look a this list specifying which applications use which system.
References:
units
man page