<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Fun Fat Studios</title>
    <description>The latest articles on DEV Community by Fun Fat Studios (@funfatstudios).</description>
    <link>https://dev.to/funfatstudios</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4254309%2Fc4438692-1acd-4641-8b13-83e61252cfcc.png</url>
      <title>DEV Community: Fun Fat Studios</title>
      <link>https://dev.to/funfatstudios</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/funfatstudios"/>
    <language>en</language>
    <item>
      <title>Your "49 KB" file is actually 50.5 KB. Blame the kilobyte.</title>
      <dc:creator>Fun Fat Studios</dc:creator>
      <pubDate>Thu, 19 Nov 2026 17:59:51 +0000</pubDate>
      <link>https://dev.to/funfatstudios/your-49-kb-file-is-actually-505-kb-blame-the-kilobyte-8hk</link>
      <guid>https://dev.to/funfatstudios/your-49-kb-file-is-actually-505-kb-blame-the-kilobyte-8hk</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;It isn't broken, exactly. You and the user just disagree about what a kilobyte is. And honestly? Both of you are right.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two kilobytes, one label
&lt;/h2&gt;

&lt;p&gt;There are two definitions in everyday use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;KB (kilobyte), SI/decimal:&lt;/strong&gt; 1,000 bytes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;KiB (kibibyte), IEC/binary:&lt;/strong&gt; 1,024 bytes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who counts which way
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Windows Explorer&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;macOS&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linux / GNU coreutils&lt;/strong&gt; gives you both. &lt;code&gt;ls -lh&lt;/code&gt;, &lt;code&gt;du -h&lt;/code&gt; and &lt;code&gt;df -h&lt;/code&gt; use powers of 1,024. Add &lt;code&gt;--si&lt;/code&gt; and you get powers of 1,000. Here's a 51,000-byte file with coreutils 9.7:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ 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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the capital &lt;code&gt;K&lt;/code&gt; versus lowercase &lt;code&gt;k&lt;/code&gt;. That's the only hint you get. Also notice &lt;code&gt;-h&lt;/code&gt; printed 50K for something that's 49.8 KiB, so it rounded up. Rounding is its own little trap on top of everything else.&lt;/p&gt;

&lt;h2&gt;
  
  
  The arithmetic
&lt;/h2&gt;

&lt;p&gt;Take a file that's exactly &lt;strong&gt;50,500 bytes&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Decimal: 50,500 / 1,000 = &lt;strong&gt;50.5 KB&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Binary: 50,500 / 1,024 = &lt;strong&gt;49.3 KiB&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;The 51,000-byte file from above works the same way: 51.0 KB in decimal, 49.8 KiB in binary.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the server actually counts
&lt;/h2&gt;

&lt;p&gt;HTML can't enforce this for you. &lt;code&gt;&amp;lt;input type="file"&amp;gt;&lt;/code&gt; supports &lt;code&gt;accept&lt;/code&gt;, &lt;code&gt;capture&lt;/code&gt; and &lt;code&gt;multiple&lt;/code&gt;, 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.&lt;/p&gt;

&lt;p&gt;And servers mostly think in 1,024.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PHP:&lt;/strong&gt; &lt;code&gt;upload_max_filesize&lt;/code&gt; and &lt;code&gt;post_max_size&lt;/code&gt; accept shorthand. The PHP manual says plainly that &lt;code&gt;1K&lt;/code&gt; = 1,024 bytes and &lt;code&gt;1M&lt;/code&gt; = 1,048,576 bytes, and even adds a note that the IEC would call this a kibibyte. So &lt;code&gt;upload_max_filesize = 50K&lt;/code&gt; means 51,200 bytes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;nginx:&lt;/strong&gt; &lt;code&gt;client_max_body_size 50k&lt;/code&gt; also means 51,200 bytes. The docs list &lt;code&gt;k&lt;/code&gt;/&lt;code&gt;K&lt;/code&gt; as kilobytes without saying how many bytes that is, but the parser in nginx's source (&lt;code&gt;ngx_parse_size&lt;/code&gt;) multiplies by 1,024. Go over and you get a 413.&lt;/p&gt;

&lt;p&gt;So here's the fun bit. A PHP or nginx config that says "50K" allows 51,200 bytes, while a hand-written check like &lt;code&gt;if (size &amp;gt; 50000)&lt;/code&gt; 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multipart overhead
&lt;/h2&gt;

&lt;p&gt;One more wrinkle. nginx's &lt;code&gt;client_max_body_size&lt;/code&gt; applies to the whole request body, not the file. PHP's &lt;code&gt;post_max_size&lt;/code&gt; covers all the POST data too. A &lt;code&gt;multipart/form-data&lt;/code&gt; body wraps each file in boundary lines plus &lt;code&gt;Content-Disposition&lt;/code&gt; and &lt;code&gt;Content-Type&lt;/code&gt; headers (RFC 7578 describes the format).&lt;/p&gt;

&lt;p&gt;How much does that add? Sending that 51,000-byte file with &lt;code&gt;curl -F&lt;/code&gt; 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 &lt;strong&gt;one byte&lt;/strong&gt;. A file a couple hundred bytes bigger, still "under 50K" by any reading, gets a 413.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to actually do
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Write limits in bytes in your config and code.&lt;/strong&gt; &lt;code&gt;51200&lt;/code&gt; or &lt;code&gt;50000&lt;/code&gt;. Pick one on purpose, not by accident of shorthand.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Show both in the UI if you show units at all.&lt;/strong&gt; "Max 50,000 bytes (about 48.8 KiB)" is ugly but nobody will argue with it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate client-side with &lt;code&gt;File.size&lt;/code&gt;.&lt;/strong&gt; MDN: it returns the size in bytes. No units to misread.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MAX_BYTES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;50_000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"change"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;MAX_BYTES&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`That file is ${file.size.toLocaleString()} bytes. The limit is ${MAX_BYTES.toLocaleString()}.`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That check is for the user's benefit only. Keep the server check, since anyone can skip your JavaScript.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Leave a margin.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The main thing is to stop writing "KB" alone anywhere a limit gets enforced. Bytes are boring. Boring doesn't generate tickets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Microsoft, The Old New Thing: &lt;a href="https://devblogs.microsoft.com/oldnewthing/?p=17933" rel="noopener noreferrer"&gt;Why does Explorer use the term KB instead of KiB?&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Apple Support: &lt;a href="https://support.apple.com/en-us/102119" rel="noopener noreferrer"&gt;How storage capacity is measured on Apple devices&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;GNU coreutils manual: &lt;a href="https://www.gnu.org/software/coreutils/manual/html_node/Block-size.html" rel="noopener noreferrer"&gt;Block size&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;PHP manual: &lt;a href="https://www.php.net/manual/en/faq.using.php" rel="noopener noreferrer"&gt;Shorthand byte values (FAQ)&lt;/a&gt; and &lt;a href="https://www.php.net/manual/en/ini.core.php" rel="noopener noreferrer"&gt;core php.ini directives&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;nginx docs: &lt;a href="https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size" rel="noopener noreferrer"&gt;client_max_body_size&lt;/a&gt;, &lt;a href="https://nginx.org/en/docs/syntax.html" rel="noopener noreferrer"&gt;measurement units&lt;/a&gt;, and &lt;a href="https://github.com/nginx/nginx/blob/master/src/core/ngx_parse.c" rel="noopener noreferrer"&gt;ngx_parse.c source&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;MDN: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob/size" rel="noopener noreferrer"&gt;Blob.size&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/file" rel="noopener noreferrer"&gt;&lt;code&gt;&amp;lt;input type="file"&amp;gt;&lt;/code&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;RFC 7578: &lt;a href="https://www.rfc-editor.org/rfc/rfc7578" rel="noopener noreferrer"&gt;Returning Values from Forms: multipart/form-data&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Disclosure: this article was drafted with AI assistance and fact-checked against the linked docs.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>abotwrotethis</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
