Ask most people how many bytes are in a kilobyte and you will get 1,000. Ask a firmware engineer and you will get 1,024, followed by a sigh. Both answers are defensible, which is exactly the problem — and it is a problem that still costs real hours in embedded and IoT projects.
Why memory landed on powers of two
Computer memory is addressed in binary. A chip with 10 address lines can select 2^10 distinct locations, and 2^10 is 1,024. Add an address line and you double it: 2,048, 4,096, 8,192. Memory capacities do not arrive at round decimal numbers because nothing in the hardware produces round decimal numbers — the address decoder counts in twos, all the way down.
So when engineers in the late 1950s and 1960s needed a shorthand for "1,024 bytes," they reached for the nearest thing at hand: the SI prefix kilo, meaning 1,000. The error was only 2.4 percent, nobody was measuring anything to that precision, and the convention stuck hard enough that sixty years later it is still the default in every discussion about RAM.
The trouble is that the error compounds. A megabyte at 2^20 is 1,048,576 — 4.9 percent off. A gigabyte at 2^30 is off by 7.4 percent. A terabyte at 2^40 is off by 10 percent. The bigger storage gets, the wider the gap between the two definitions grows.
The 1998 fix almost nobody adopted
In 1998 the International Electrotechnical Commission published binary prefixes to end the ambiguity: kibibyte (KiB) = 1,024 bytes, mebibyte (MiB) = 1,048,576 bytes, gibibyte (GiB), tebibyte (TiB), and so on. Under that scheme kilobyte means exactly 1,000 bytes and kibibyte means exactly 1,024, with no overlap.
It is a clean solution. It is also, outside of standards documents and a handful of Linux tools, almost entirely ignored. Most datasheets, marketing pages, and engineers still say "KB" and leave you to infer which one they meant from context.
Where the two definitions collide
The most familiar collision happens on the desktop. Storage manufacturers sell in decimal, so a "1 TB" SSD contains 1,000,000,000,000 bytes. Windows reports capacity in binary units while still labelling them "GB," so it divides by 2^30 and shows roughly 931. No bytes went missing; two different definitions were applied to the same number. macOS sidestepped the complaint in 2009 by switching to decimal reporting, which is why the same drive reads differently on the two operating systems.
In embedded work the collision is less cosmetic. Flash and RAM on a microcontroller are genuinely binary — always. When an ESP32 module is described as having 4 MB of flash, that is 4,194,304 bytes, not 4,000,000. The 194,304-byte difference is not a rounding curiosity; it is roughly the size of a small OTA staging slot.
That matters the moment you write a partition table. Over-the-air update schemes typically need two application slots plus an NVS region and a filesystem partition, all of which have to fit inside real flash with alignment respected. Size those partitions with decimal arithmetic and the numbers will look fine in a spreadsheet, then fail at flash time — or worse, pass on the bench and fail on the first field update, when a device tries to stage an image that does not fit. Debugging that from a rooftop sensor node in Cebu is a genuinely bad afternoon.
The same trap shows up in throughput budgeting. Cellular and LPWAN plans are usually sold in decimal megabytes, while your firmware counts payload buffers in binary. If your monthly data budget is calculated one way and your telemetry accounting the other, the 4.9 percent gap quietly eats your margin.
The practical rule
Assume binary for anything inside the device — RAM, flash, buffers, partition tables, filesystem images. Assume decimal for anything sold to you by a vendor — drive capacity, data plans, network speeds. When you write the numbers down for someone else, write the actual byte count next to the unit. 4 MB (4,194,304 bytes) takes three seconds to type and removes the ambiguity permanently.
It is a small discipline, and it is the kind of thing that separates firmware that survives its first OTA campaign from firmware that does not. If you are planning an IoT deployment and want the flash budget sized correctly before boards get ordered, talk to us about your project — partition planning is part of how we approach embedded and IoT development, from silicon to cloud.
Top comments (0)