<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Fun Fat Studios]]></title><description><![CDATA[Fun Fat Studios]]></description><link>https://funfatstudios.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 26 Nov 2026 11:36:39 GMT</lastBuildDate><atom:link href="https://funfatstudios.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Your "49 KB" file is actually 50.5 KB. Blame the kilobyte.]]></title><description><![CDATA[A user picks a file. Their computer says 49 KB. Your form says "max 50 KB." The upload gets rejected anyway, and now there's a support ticket that says…]]></description><link>https://funfatstudios.hashnode.dev/your-49-kb-file-is-actually-50-5-kb-blame-the-kilobyte</link><guid isPermaLink="true">https://funfatstudios.hashnode.dev/your-49-kb-file-is-actually-50-5-kb-blame-the-kilobyte</guid><category><![CDATA[webdev]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Beginner Developers]]></category><dc:creator><![CDATA[Fun Fat Studios]]></dc:creator><pubDate>Tue, 24 Nov 2026 18:57:27 GMT</pubDate><content:encoded><![CDATA[<p>A user picks a file. Their computer says 49 KB. Your form says "max 50 KB." The upload gets rejected anyway, and now there's a support ticket that says your site is broken.</p>
<p>It isn't broken, exactly. You and the user just disagree about what a kilobyte is. And honestly? Both of you are right.</p>
<h2>Two kilobytes, one label</h2>
<p>There are two definitions in everyday use:</p>
<ul>
<li><strong>KB (kilobyte), SI/decimal:</strong> 1,000 bytes</li>
<li><strong>KiB (kibibyte), IEC/binary:</strong> 1,024 bytes</li>
</ul>
<p>The IEC prefixes (KiB, MiB, GiB) exist precisely to separate the two. Almost nobody uses them in a UI, though. So "KB" on a screen could mean either one, and you usually can't tell which by looking.</p>
<h2>Who counts which way</h2>
<p><strong>Windows Explorer</strong> uses 1,024 and calls it KB. Raymond Chen explained why on Microsoft's own blog years ago: everybody else said KB for 1,024 too, so Explorer followed existing practice. That's still the behaviour.</p>
<p><strong>macOS</strong> went decimal. Apple's support page on storage capacity says OS X Leopard and earlier reported sizes in binary, which means everything from Snow Leopard (10.6) on counts 1 KB as 1,000 bytes. Same file, different number than on Windows.</p>
<p><strong>Linux / GNU coreutils</strong> gives you both. <code>ls -lh</code>, <code>du -h</code> and <code>df -h</code> use powers of 1,024. Add <code>--si</code> and you get powers of 1,000. Here's a 51,000-byte file with coreutils 9.7:</p>
<pre><code>$ ls -l photo.jpg
-rw-r--r-- 1 box box 51000 Nov 19 12:48 photo.jpg
$ ls -lh photo.jpg
-rw-r--r-- 1 box box 50K Nov 19 12:48 photo.jpg
$ ls -lh --si photo.jpg
-rw-r--r-- 1 box box 51k Nov 19 12:48 photo.jpg
</code></pre>
<p>Notice the capital <code>K</code> versus lowercase <code>k</code>. That's the only hint you get. Also notice <code>-h</code> printed 50K for something that's 49.8 KiB, so it rounded up. Rounding is its own little trap on top of everything else.</p>
<h2>The arithmetic</h2>
<p>Take a file that's exactly <strong>50,500 bytes</strong>.</p>
<ul>
<li>Decimal: 50,500 / 1,000 = <strong>50.5 KB</strong></li>
<li>Binary: 50,500 / 1,024 = <strong>49.3 KiB</strong></li>
</ul>
<p>On a machine doing 1,024 math, that looks like a "49 KB" file. If your server rejects anything over 50,000 bytes, it fails. The user isn't lying and your code isn't buggy. You're just using different rulers.</p>
<p>The 51,000-byte file from above works the same way: 51.0 KB in decimal, 49.8 KiB in binary.</p>
<h2>What the server actually counts</h2>
<p>HTML can't enforce this for you. <code>&lt;input type="file"&gt;</code> supports <code>accept</code>, <code>capture</code> and <code>multiple</code>, and that's it. There's no size attribute. Any size limit lives in JavaScript or on the server, and the server is the one that counts.</p>
<p>And servers mostly think in 1,024.</p>
<p><strong>PHP:</strong> <code>upload_max_filesize</code> and <code>post_max_size</code> accept shorthand. The PHP manual says plainly that <code>1K</code> = 1,024 bytes and <code>1M</code> = 1,048,576 bytes, and even adds a note that the IEC would call this a kibibyte. So <code>upload_max_filesize = 50K</code> means 51,200 bytes.</p>
<p><strong>nginx:</strong> <code>client_max_body_size 50k</code> also means 51,200 bytes. The docs list <code>k</code>/<code>K</code> as kilobytes without saying how many bytes that is, but the parser in nginx's source (<code>ngx_parse_size</code>) multiplies by 1,024. Go over and you get a 413.</p>
<p>So here's the fun bit. A PHP or nginx config that says "50K" allows 51,200 bytes, while a hand-written check like <code>if (size &gt; 50000)</code> allows 50,000. Two different limits, both called "50 KB." I'd bet plenty of apps have exactly this mismatch between their help text and their config.</p>
<h2>Multipart overhead</h2>
<p>One more wrinkle. nginx's <code>client_max_body_size</code> applies to the whole request body, not the file. PHP's <code>post_max_size</code> covers all the POST data too. A <code>multipart/form-data</code> body wraps each file in boundary lines plus <code>Content-Disposition</code> and <code>Content-Type</code> headers (RFC 7578 describes the format).</p>
<p>How much does that add? Sending that 51,000-byte file with <code>curl -F</code> produced a 51,199-byte body. About 200 bytes of overhead, which grows with longer field names, filenames and extra fields. Against a 51,200-byte nginx limit, that upload squeaks through by <strong>one byte</strong>. A file a couple hundred bytes bigger, still "under 50K" by any reading, gets a 413.</p>
<h2>What to actually do</h2>
<ol>
<li><strong>Write limits in bytes in your config and code.</strong> <code>51200</code> or <code>50000</code>. Pick one on purpose, not by accident of shorthand.</li>
<li><strong>Show both in the UI if you show units at all.</strong> "Max 50,000 bytes (about 48.8 KiB)" is ugly but nobody will argue with it.</li>
<li><strong>Validate client-side with <code>File.size</code>.</strong> MDN: it returns the size in bytes. No units to misread.</li>
</ol>
<pre><code class="language-js">const MAX_BYTES = 50_000;

input.addEventListener("change", () =&gt; {
  const file = input.files[0];
  if (file &amp;&amp; file.size &gt; MAX_BYTES) {
    alert(`That file is ${file.size.toLocaleString()} bytes. The limit is ${MAX_BYTES.toLocaleString()}.`);
    input.value = "";
  }
});
</code></pre>
<p>That check is for the user's benefit only. Keep the server check, since anyone can skip your JavaScript.</p>
<ol start="4">
<li><strong>Leave a margin.</strong> If your server cap is 51,200 bytes for the whole body, don't advertise 51,200 bytes per file. Advertise less and leave room for multipart overhead and other form fields.</li>
</ol>
<p>The main thing is to stop writing "KB" alone anywhere a limit gets enforced. Bytes are boring. Boring doesn't generate tickets.</p>
<h2>Sources</h2>
<ul>
<li>Microsoft, The Old New Thing: <a href="https://devblogs.microsoft.com/oldnewthing/?p=17933">Why does Explorer use the term KB instead of KiB?</a></li>
<li>Apple Support: <a href="https://support.apple.com/en-us/102119">How storage capacity is measured on Apple devices</a></li>
<li>GNU coreutils manual: <a href="https://www.gnu.org/software/coreutils/manual/html_node/Block-size.html">Block size</a></li>
<li>PHP manual: <a href="https://www.php.net/manual/en/faq.using.php">Shorthand byte values (FAQ)</a> and <a href="https://www.php.net/manual/en/ini.core.php">core php.ini directives</a></li>
<li>nginx docs: <a href="https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size">client_max_body_size</a>, <a href="https://nginx.org/en/docs/syntax.html">measurement units</a>, and <a href="https://github.com/nginx/nginx/blob/master/src/core/ngx_parse.c">ngx_parse.c source</a></li>
<li>MDN: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob/size">Blob.size</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/file"><code>&lt;input type="file"&gt;</code></a></li>
<li>RFC 7578: <a href="https://www.rfc-editor.org/rfc/rfc7578">Returning Values from Forms: multipart/form-data</a></li>
</ul>
<p><em>We make UploadReady, a free-to-download Android app (with an optional one-time Pro unlock) for fixing photos and PDFs that portals reject for size or format. If that's your problem from the other side of the form, it's here: <a href="https://play.google.com/store/apps/details?id=com.funfatstudios.uploadready&amp;pcampaignid=web_share">UploadReady on Google Play</a>.</em></p>
<p><em>Disclosure: this article was drafted with AI assistance and fact-checked against the linked docs. Originally published on <a href="https://dev.to/funfatstudios/your-49-kb-file-is-actually-505-kb-blame-the-kilobyte-8hk">DEV</a>.</em></p>
]]></content:encoded></item></channel></rss>