File Size Unit Reference
A conversion cheatsheet for B / KB / KiB / MB / MiB / GB / GiB. Useful for code, config, and test design.
SI units (decimal) vs. IEC units (binary)
File size units come in two flavours: the decimal SI units, and the binary IEC units. The most common pitfall — confusing MB with MiB — is the source of many failed boundary-value tests.
| SI | Reads | Bytes | IEC | Reads | Bytes | Diff |
|---|---|---|---|---|---|---|
| KB | kilobyte | 1,000 | KiB | kibibyte | 1,024 | +2.4% |
| MB | megabyte | 1,000,000 | MiB | mebibyte | 1,048,576 | +4.86% |
| GB | gigabyte | 1,000,000,000 | GiB | gibibyte | 1,073,741,824 | +7.37% |
| TB | terabyte | 1,000,000,000,000 | TiB | tebibyte | 1,099,511,627,776 | +9.95% |
MB → bytes lookup
| MB (decimal) | Bytes | MiB (binary) | Bytes |
|---|---|---|---|
| 0.1 MB | 100,000 B | 0.1 MiB | 104,858 B |
| 0.5 MB | 500,000 B | 0.5 MiB | 524,288 B |
| 1 MB | 1,000,000 B | 1 MiB | 1,048,576 B |
| 2 MB | 2,000,000 B | 2 MiB | 2,097,152 B |
| 5 MB | 5,000,000 B | 5 MiB | 5,242,880 B |
| 10 MB | 10,000,000 B | 10 MiB | 10,485,760 B |
| 20 MB | 20,000,000 B | 20 MiB | 20,971,520 B |
| 25 MB | 25,000,000 B | 25 MiB | 26,214,400 B |
| 50 MB | 50,000,000 B | 50 MiB | 52,428,800 B |
| 100 MB | 100,000,000 B | 100 MiB | 104,857,600 B |
| 256 MB | 256,000,000 B | 256 MiB | 268,435,456 B |
| 512 MB | 512,000,000 B | 512 MiB | 536,870,912 B |
| 1 GB | 1,000,000,000 B | 1 GiB | 1,073,741,824 B |
How major services and tools interpret unit suffixes
| Service / setting | Suffix | Actual interpretation | Example |
|---|---|---|---|
| PHP (php.ini) | M | MiB (binary) | 10M = 10,485,760 B |
| Nginx (client_max_body_size) | m | MiB (binary) | 10m = 10,485,760 B |
| Apache (LimitRequestBody) | raw bytes | raw bytes | 10485760 = 10 MiB |
| Windows Explorer | shows "MB" | computes in MiB (binary) | "9.99 MB" = 10,476,544 B |
| macOS Finder | shows "MB" | uses MB (decimal) | "10 MB" = 10,000,000 B |
| Linux (ls -lh) | M | MiB (binary) | 10M = 10 MiB |
| Gmail attachment limit | 25 MB | MB (decimal) | 25,000,000 B |
| AWS S3 console | MiB shown | MiB (binary) | as displayed |
Conversion code
// JavaScript
const UNITS = {
// SI (decimal)
KB: 1_000, MB: 1_000_000, GB: 1_000_000_000, TB: 1_000_000_000_000,
// IEC (binary)
KiB: 1_024, MiB: 1_048_576, GiB: 1_073_741_824, TiB: 1_099_511_627_776,
};
const toBytes = (value, unit) => value * UNITS[unit];
const fromBytes = (bytes, unit) => bytes / UNITS[unit];
// 10 MiB → bytes
console.log(toBytes(10, 'MiB')); // → 10485760
// 10,000,000 B → MB
console.log(fromBytes(10_000_000, 'MB')); // → 10
console.log(fromBytes(10_000_000, 'MiB').toFixed(2)); // → 9.54
1_000, 'MB' => 1_000_000, 'GB' => 1_000_000_000,
'KiB' => 1_024, 'MiB' => 1_048_576, 'GiB' => 1_073_741_824,
];
return (int)($value * ($units[$unit] ?? 1));
}
echo toBytes(10, 'MiB'); // → 10485760
echo toBytes(25, 'MB'); // → 25000000
Boundary-value test files
DevLab provides byte-precise test files for the most common upload limits. Pick the file that matches the unit interpretation you're testing against.
- Threshold test files — sets of files just under, exactly at, and just over each common limit.