Why My Compressor Said 49KB and My Phone Said 51KB
I built pic2kb (https://pic2kb.com/en/) to compress an image to an exact size: you type 50, you get a file that fits a 50KB limit. So when I opened it on my iPhone, ran a photo through it, and the page reported 49KB, I expected the file to be 49KB.
Then I opened the file in iOS Files. It said 51KB.
The downloaded filename said image-49.9kb.jpg. Three numbers, one file: 49, 49.9, and 51.
First question: did my compressor overshoot?
My instinct was that the “must be ≤ target” check had a bug. Before touching code, I reproduced the arithmetic in Node.
A file of about 51,097 bytes:
- divided by 1024 → 49.9 (what my filename used)
- divided by 1000 → 51.1 (what iOS Files displayed, rounded to 51)
So all three numbers describe the same byte count. Nothing was miscalculated. The file was simply being labelled with two different definitions of a kilobyte.
KB vs KiB: 1024 or 1000 bytes?
- Binary: 1 KB = 1024 bytes. Early computing grouped memory in powers of two, and 2¹⁰ = 1024 is close to 1000. Strictly this unit is a kibibyte (KiB), but almost everyone still writes “KB”.
- Decimal (SI): 1 KB = 1000 bytes. Storage makers and standards bodies preferred round numbers; kilo means 1000.
For one kilobyte the gap is 24 bytes, about 2.4%. It compounds at megabytes, because the two conventions diverge again at that step:
- 1 binary MB = 1024 × 1024 = 1,048,576 bytes
- 1 decimal MB = 1000 × 1000 = 1,000,000 bytes
That is roughly a 4.9% difference. iOS and Android file details, and macOS Finder, report decimal sizes. Windows has historically reported binary. For a browser tool either convention is defensible.
| Value | Decimal (SI) | Binary (IEC) | Gap |
|---|---|---|---|
| 1 KB | 1,000 bytes | 1,024 bytes (1 KiB) | 2.4% |
| 50 KB | 50,000 bytes | 51,200 bytes | 2.4% |
| 1 MB | 1,000,000 bytes | 1,048,576 bytes (1 MiB) | 4.9% |
| 1 GB | 1,000,000,000 bytes | 1,073,741,824 bytes (1 GiB) | 7.4% |
That is why the same “50KB” limit can be enforced as 50,000 bytes by one portal and understood as 51,200 by the tool that prepared the file.
Why this was more than a cosmetic problem
Application portals do not read the “KB” label. Their server receives the raw bytes and compares them against a limit baked into the form. A portal that enforces a strict 50,000-byte or 1,000,000-byte ceiling will reject a file sized to the binary convention, even though the tool that produced it displayed a number at or under the target.
That is the part that would have hurt users: not a number looking odd on screen, but a rejected application form.
Choosing the fix
I wrote up two options.
Option A — switch the whole site to decimal. It would mean changing the engine’s target calculation, the seven places that format sizes, and the size display in five other tools. Cost: about 2.4% less quality headroom, since we would be aiming at a smaller byte budget. Benefit: page, filename and file properties would all agree everywhere.
Option B — keep the engine’s internal binary arithmetic, but reserve a margin so the output still fits the decimal number the user has in mind, and explain the difference in the UI with a link to an article.
I preferred B because the internal arithmetic was fine and I did not want a wide refactor. But first I had to check whether a single margin factor would work.
It would not. My first guess was 0.97, and it was wrong for the MB tiers — because those get scaled twice. The page maps “1MB” to a target of 1024, the engine multiplies by 1024 again, giving 1,048,576; times 0.97 that is still 1,017,119 bytes, over the decimal 1,000,000. The required factors differ by tier: 0.9766 for KB tiers, 0.9537 for MB tiers. A single constant cannot be both safe and tight.
What I shipped
The engine now aims at the decimal byte count for the unit the user actually meant:
- KB targets (typed values and all KB tier pages): target × 1000 bytes.
- MB tier pages: the page declares the unit, so 1MB means 1,000,000 bytes rather than 1,048,576.
- The “make it bigger” mode is untouched. It raises a file to at least a minimum, where a larger byte count is safer — applying the same margin there could have delivered less than the label promises.
The displayed size also moved to decimal, so the result panel, the filename and the file properties in iOS, Android, macOS and Windows now tell the same story. Under the download button there is one line explaining that sizes can differ very slightly between systems, linking to a short article on why.
Verification was mostly mechanical: the algorithm suite, the compression core (including a new case that pins the MB and KB thresholds to separate values), a full-site link check, and a browser run that compresses real images on the tier pages. The 50KB page now produces a file of about 48.9KB — comfortably inside 50,000 bytes. If what you need is to land on an exact size in the first place, that is a separate problem — I wrote about it in Why Most Compressors Can’t Hit 50KB.
What I took from it
A file’s size has no single answer: it is a number as interpreted by whichever system is describing it. Nobody cares which convention is technically correct — only that the number on the form matches the one they see.
The other lesson was about sequencing. I nearly started rewriting the size logic before I had reproduced the three numbers in a script. Ten lines of code showed it was a labelling problem, not a compression problem, and that reframing is what led to a fix small enough to ship the same day.