Skip to content

MB and MiB Are Different! Pitfalls of File Size Units

Category: Fundamentals

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 48,576 bytes (approximately 4.86%). 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 9.9 × 1,048,576 = 10,381,301 bytes. 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 upload_max_filesize = 10M (=10MiB = 10,485,760 bytes).

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 upload_max_filesize = 10M → limit is 10,485,760 bytes (10 MiB)
  • Gmail attachment limit → The limit is 25,000,000 bytes (25 MB)
  • Discord's free plan → limit is 25,000,000 bytes (25 MB)

The threshold test files on DevLab provide files with precise sizes in bytes. Check your server configuration before testing and select the corresponding threshold file.

Summary

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

File size unit conversion table is here

Test files for this article

❓ Frequently Asked Questions

What is the difference between MB and MiB?
MB is the SI, decimal unit: 1 MB = 1,000,000 bytes. MiB is the IEC, binary unit: 1 MiB = 1,048,576 bytes. The gap is about 4.86%, so 10 MB and 10 MiB differ by roughly 485 KB.
How many bytes is 10M in PHP's upload_max_filesize?
php.ini reads 10M as 10 MiB, or 10,485,760 bytes. Nginx does the same: 10m in client_max_body_size is 10 MiB. Attachment limits like the 25 MB on Gmail and Discord, by contrast, are decimal — 25,000,000 bytes.
Do Windows and macOS report file sizes differently?
Yes. Windows Explorer writes MB but actually calculates in MiB, units of 1,048,576 bytes. macOS Finder shows true MB, units of 1,000,000 bytes. The same file therefore reads as a different size depending on the operating system.