DevToys Web Pro iconDevToys Web ProBlog
Traduzido com LocalePack logoLocalePack
Avalie-nos:
Experimente a extensão do navegador:
← Back to Blog

Data Size Converter Guide: Bytes, KB vs KiB, Binary vs Decimal Units

8 min read

A 1 TB hard drive shows up as 931 GB in Windows Explorer. A file your API reports as 5 MB transfers at 625 KB/s even though your ISP advertises 5 Mbps. These are not bugs — they are the result of two competing unit systems that have coexisted uneasily for decades. Use the Data Size Converter to follow along and convert between units as you read.

IEC Binary Prefixes vs SI Decimal Prefixes

The confusion starts with the prefix kilo. In the SI (International System of Units), kilo means exactly 1,000 — one kilometer is 1,000 meters, one kilogram is 1,000 grams. Early computer engineers borrowed these prefixes but rounded to the nearest power of two because binary arithmetic made powers of two natural boundaries. One "kilobyte" became 1,024 bytes (210), not 1,000.

This worked informally until storage capacities grew large enough that the 2.4% rounding error per prefix level compounded into visible discrepancies. In 1998, the International Electrotechnical Commission (IEC) published IEC 80000-13, which introduced unambiguous binary prefixes:

  • KiB (kibibyte) = 210 = 1,024 bytes
  • MiB (mebibyte) = 220 = 1,048,576 bytes
  • GiB (gibibyte) = 230 = 1,073,741,824 bytes
  • TiB (tebibyte) = 240 bytes

Under this standard, KB means exactly 1,000 bytes (SI decimal) and KiB means 1,024 bytes (IEC binary). The standard is unambiguous. The industry is not.

Unit Reference Table

Decimal unitDecimal valueBinary unitBinary value
KB (kilobyte)1,000 BKiB (kibibyte)1,024 B
MB (megabyte)1,000,000 BMiB (mebibyte)1,048,576 B
GB (gigabyte)1,000,000,000 BGiB (gibibyte)1,073,741,824 B
TB (terabyte)1012 BTiB (tebibyte)240 B ≈ 1.0995 × 1012 B
PB (petabyte)1015 BPiB (pebibyte)250 B
EB (exabyte)1018 BEiB (exbibyte)260 B
ZB (zettabyte)1021 BZiB (zebibyte)270 B
YB (yottabyte)1024 BYiB (yobibyte)280 B

At the kilobyte level the difference is only 2.4%. At terabyte scale it reaches 9.1%, which is why the hard drive discrepancy is so noticeable.

Why That 1 TB Drive Shows 931 GiB

Hard drive manufacturers — and storage standards bodies like JEDEC for SSDs — label capacity using decimal prefixes. A "1 TB" drive contains exactly 1,000,000,000,000 bytes. Windows (until recently) and Linux report drive sizes in binary units but label them "GB". So Windows divides 1012 bytes by 230 to get 931.32 and calls it "931 GB" — meaning 931 GiB by the IEC standard.

The drive is not short-changing you. The label is just using a different unit than the OS display. The actual byte count is the same.

Quick formula: decimal GB ÷ 1.0737 = binary GiB. A 500 GB drive shows as approximately 465 GiB.

Bits vs Bytes: Network Bandwidth vs Download Speed

Network bandwidth is measured in bits per second. Download speed is typically shown in bytes per second. There are 8 bits in one byte.

A 100 Mbps (megabits per second) internet connection delivers a maximum of 100 ÷ 8 = 12.5 MB/s (megabytes per second) of actual file data. Telecommunications companies use bits because the numbers look larger and match the physical signaling rate. Operating systems show bytes because files are measured in bytes.

When your ISP advertises "1 Gbps" broadband, your download manager will cap out around 125 MB/s under ideal conditions. If you see speeds in Mbps in your OS, check whether the application is reporting megabits or megabytes — the unit matters by a factor of eight.

Historical Baggage

The 1.44 MB floppy disk is a famous example of mixed conventions. It was neither 1.44 × 106 bytes (decimal MB) nor 1.44 × 220 bytes (binary MiB). The actual formatted capacity was 1,474,560 bytes — which is 1,440 KiB, or about 1.41 MiB, or about 1.47 MB. The "1.44" label came from multiplying 80 tracks × 18 sectors × 2 sides × 512 bytes/sector, then dividing by 1,000 (not 1,024) for the "MB" suffix — a hybrid that fit neither system cleanly.

Before IEC 80000-13, "KB" almost universally meant 1,024 bytes in software contexts. Compilers, operating systems, and documentation all used the binary meaning silently. Post-standard, the technically correct term for 1,024 bytes is KiB, but old habits persist: RAM is still routinely described in "GB" meaning GiB by hardware vendors, and many developers write "MB" when they mean "MiB" in source code comments.

When to Use Which Unit in Code

There is no single right answer — context determines the correct unit. Three common scenarios:

  • File sizes displayed to users: Use binary units (KiB, MiB, GiB) and label them correctly. This matches what the OS file manager shows, which avoids confusion when users compare your app's display to Finder or Explorer. If you must use "KB" for a familiar label, divide by 1,024 — not 1,000.
  • Network transfers and API rate limits: ISPs and cloud providers (AWS S3, Cloudflare, etc.) bill and advertise in decimal units. A 5 GB/month data cap is 5,000,000,000 bytes. Use decimal when communicating with external systems or documenting API limits that reference provider specs.
  • RAM and CPU cache: Always binary. Memory controllers operate on powers of two. 8 GB of RAM is 8 GiB = 8,589,934,592 bytes. No RAM chip ships in non-power-of-two sizes.

Formatting Helpers

Modern JavaScript has a built-in way to format byte values as human-readable strings using Intl.NumberFormat:

// Intl.NumberFormat with byte units (Chrome 77+, Node 12+)
const fmt = new Intl.NumberFormat('en', {
  notation: 'compact',
  style: 'unit',
  unit: 'byte',
  unitDisplay: 'narrow',
});
// Note: browser support for 'byte' unit is limited — use a library for reliable results

For reliable cross-environment formatting, the filesize npm package is the standard choice:

npm install filesize
import { filesize } from 'filesize';

filesize(1000);        // "1 kB"  (decimal by default)
filesize(1024);        // "1.02 kB"
filesize(1024, { standard: 'iec' });  // "1 KiB"
filesize(1073741824);  // "1.07 GB"
filesize(1073741824, { standard: 'iec' });  // "1 GiB"

Code Examples

A minimal JavaScript function that formats a byte count for display to end users using binary units:

/**
 * Format a byte count as a human-readable binary size string.
 * Uses IEC units (KiB, MiB, GiB, …) to match OS file managers.
 */
function formatBytes(bytes, decimals = 1) {
  if (bytes === 0) return '0 B';
  const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
  const i = Math.floor(Math.log(bytes) / Math.log(1024));
  return (bytes / Math.pow(1024, i)).toFixed(decimals) + ' ' + units[i];
}

formatBytes(0);           // "0 B"
formatBytes(1023);        // "1023.0 B"
formatBytes(1024);        // "1.0 KiB"
formatBytes(1048576);     // "1.0 MiB"
formatBytes(1500000000);  // "1.4 GiB"

Python equivalent using the humanize package:

import humanize

humanize.naturalsize(1073741824)                    # '1.1 GB'  (decimal)
humanize.naturalsize(1073741824, binary=True)       # '1.0 GiB' (binary)
humanize.naturalsize(1073741824, gnu=True)          # '1.0G'    (GNU-style)

On the command line, ls -lh and du -h on Linux use binary units with SI labels (showing "1.0G" for 1 GiB). macOS ls -lh behaves the same way. The --si flag on GNU coreutils switches to true decimal SI units.

# GNU coreutils
ls -lh file.iso        # 1.1G  (binary, mislabeled)
ls -lh --si file.iso   # 1.1G  (decimal SI)
du -h --block-size=MiB dir/    # explicit MiB blocks

Common Confusions by Platform

PlatformUnits usedLabels shownNotes
WindowsBinary (÷ 1024)GB, MB, KBUses binary math but SI labels — technically incorrect per IEC
macOS 10.6+Decimal (÷ 1000)GB, MB, KBApple switched to decimal in Snow Leopard to match storage vendors; pre-10.6 was binary
Linux (most distros)Binary (÷ 1024)GB, MB, KBSame pattern as Windows; GNOME Files shows GiB labels since 3.x
Hard drive specsDecimalTB, GB, MBAll major manufacturers (Seagate, WD, Samsung) use 1 TB = 10¹² bytes
RAM specsBinaryGB, MB8 GB DDR5 = 8 × 2³⁰ bytes; no ambiguity in practice
Network speedsDecimal bitsGbps, MbpsAlways bits (lowercase b), divide by 8 for bytes

macOS being decimal since Snow Leopard (10.6, 2009) is the most surprising entry for many developers. A 1 TB external drive plugged into a Mac shows ~1,000 GB in Finder — the same number printed on the box. The same drive on Windows shows ~931 GB. Neither is wrong; they use different units without saying so.


Convert between any combination of byte units — bits, bytes, KiB, MB, GiB, TB, and more — with the Data Size Converter. For a broader look at unit converters for length, weight, and temperature, see the Data Converters Guide.