Skip to content

MB and MiB Are Different! Pitfalls of File Size Units

Category: Fundamentals
This article is currently available in Japanese only. We are working on translations.

When you see a specification that says 「The file size limit is 10MB」, how do you interpret it? In fact, 「MB」 and 「MiB」 are distinctly different units, and confusion between them can cause boundary value testing failures and production incidents. This article explains the precise definitions of file size units and common pitfalls in development.

Definition of MB and MiB

There are two types of units for expressing file size: SI units (decimal-based) and IEC units (binary-based).

UnitHow to readNumber of BytesStandard
KBKilobyte1,000 BSI (decimal)
KiBKibibyte1,024 BIEC (Binary)
MBMegabyte1,000,000 BSI (decimal)
MiBMebibyte1,048,576 BIEC (Binary)
GBGigabyte1,000,000,000 BSI (decimal)
GiBGibibyte1,073,741,824 BIEC (Binary)

The difference between 1MB and 1MiB is <strong>48,576 bytes (approximately 4.86%)</strong>. For 10MB vs 10MiB, the gap grows to about 485KB. When these differences accumulate, boundary value testing can result in a situation where files that should be under 10MB are rejected.

Differences in handling across development tools, OS, and cloud platforms

What complicates matters is that different tools and operating systems interpret this unit in their own ways.

Tools / EnvironmentInterpreting 「10MB」Actual Byte Count
PHP(php.ini)10MiB10,485,760 B
Nginx(client_max_body_size)10MiB10,485,760 B
Windows ExplorerMiB notation (written as "MB")1,048,576 B / MB
macOS FinderMB (Decimal)1,000,000 B / MB
AWS S3 Management ConsoleMiB Display1,048,576 B / MB
Gmail (Attachment Limit)MB (Decimal)25,000,000 B

Particularly important to note is that Windows displays "MB" but actually calculates in "MiB". A file shown as "9.9 MB" in Windows may actually be <code>9.9 × 1,048,576 = 10,381,301 bytes</code>. This is larger than 10MB (10,000,000 bytes) and won't cause issues with Gmail (25MB limit), but it will fail to pass PHP's <code>upload_max_filesize = 10M</code> (<code>=10MiB = 10,485,760 bytes</code>).

Practical example in PHP

In PHP configuration files, units are interpreted as follows.

; php.ini の設定
upload_max_filesize = 10M   ; 10 MiB = 10,485,760 バイト
post_max_size = 12M         ; 12 MiB = 12,582,912 バイト

When validating the size of uploaded files, it is most reliable to compare values in bytes.

// バイト単位で比較(安全)
$maxBytes = 10 * 1024 * 1024; // 10 MiB = 10,485,760 バイト
if ($_FILES['file']['size'] > $maxBytes) {
    throw new \RuntimeException('ファイルサイズが上限を超えています');
}

// NG: 文字列の "10MB" を解析する場合は単位の解釈に注意

Practical Example in JavaScript

// File API では size プロパティがバイト数を返す
const file = event.target.files[0];

const MAX_SIZE_MIB = 10 * 1024 * 1024;  // 10 MiB
const MAX_SIZE_MB  = 10 * 1000 * 1000;  // 10 MB

// サーバー側に合わせて単位を統一する
if (file.size > MAX_SIZE_MIB) {
    alert(`ファイルサイズ上限は 10 MiB (${MAX_SIZE_MIB.toLocaleString()} バイト) です`);
}

Impact on boundary value testing

When testing a 「10MB limit」, it is important to understand the server's actual limit value before selecting an appropriate test file.

  • PHP <code>upload_max_filesize = 10M</code> → limit is <strong>10,485,760 bytes (10 MiB)</strong>
  • Gmail attachment limit → The limit is <strong>25,000,000 bytes (25 MB)</strong>
  • Discord's free plan → limit is <strong>25,000,000 bytes (25 MB)</strong>

The <a href="/ja/files/threshold/">threshold test files</a> on DevLab provide files with precise sizes in bytes. Check your server configuration before testing and select the corresponding threshold file.

Summary

  • <strong>MB = 1,000,000 bytes</strong> (SI units), <strong>MiB = 1,048,576 bytes</strong> (IEC units)
  • PHP and Nginx interpret "M" as <strong>MiB</strong>.
  • Windows displays "MB" but calculates in <strong>MiB</strong>
  • macOS displays <strong>MB</strong> (decimal)
  • Use precise test files measured in bytes and select them according to how server settings are interpreted

→ <a href="/ja/reference/file-size-units/">File size unit conversion table is here</a>

Test files for this article

  • → <a href="/ja/files/threshold/" class="text-primary-600 dark:text-primary-400 hover:underline">Threshold Test Files (9.9MB / 10MB / 10.1MB)</a>

Related articles

  • → <a href="/ja/blog/how-to-test-upload-limit/" class="text-primary-600 dark:text-primary-400 hover:underline">How to Properly Test File Upload Limits</a>
  • → <a href="/ja/blog/multipart-form-data-overhead/" class="text-primary-600 dark:text-primary-400 hover:underline">Calculating multipart/form-data Overhead Accurately</a>