omar.io

When technically right is wrong: Kilobytes

Jan 16, 2017

How many bytes are in a kilobyte? 1000 or 1024? The answer depends on who you ask. Google says 1 kilobyte = 1000 bytes. Hard drive manufacturers also say 1 kilobyte = 1000 bytes. However, my computer measures disk space and memory using the ratio 1 kilobyte = 1024 bytes. This discrepancy is well known and has been written about by folks like Jeff Atwood and Randall Munroe in xkcd 394.

So what’s the right answer? Well, since kilo is the SI prefix for 1000, technically, 1 kilobyte = 1000 bytes. However, 1 kilobyte = 1024 bytes in all applications of computer software and hardware like memory usage or remaining hard drive space. Given that, when I built ByteSize I opted to use the ratio 1 kilobyte = 1024 bytes. After all, the main use cases for ByteSize would be to handle byte amounts for computer memory and storage.

Almost immeditaly after I published ByteSize, a request was made to add support for decimal prefixes (i.e. support 1 kilobyte = 1000 bytes). A few months ago, a similar request was made on the Humanizer project (which ships ByteSize as an internal class) citing the discrepancy with the SI unit.

While I intend to add support for the SI ratio, I plan on keeping the ratio 1 kilobyte = 1024 bytes as the default behavior of ByteSize. Although that’s technically wrong, I believe the right path is to align with how software and hardware handle bytes. I’ve also opted to forgo the naming outlined in IEEE 1541; at least until it’s more widly adopted and people stop thinking of dog treats or Middle Eastern food when they hear “kibibytes”.