Unit ToolsΒ·5 min

How to Convert Bytes, KB, MB, GB, TB (and PB)

Understand binary vs decimal, convert between byte units, and avoid common pitfalls.

Why are there two different "MB"?

Buy a 1 TB hard drive, plug it in, and your operating system reports 931 GB. The drive is "missing" 69 GB. This is not a bug, a scam, or a format error. It is the binary vs decimal confusion baked into how we name storage.

The core issue: do you multiply by 1,000 (decimal, the SI standard) or by 1,024 (binary, what computers actually do internally)?

  • 1 KB = 1,000 bytes (decimal, what hard drive vendors use, what SI dictates)
  • 1 KiB = 1,024 bytes (binary, what Windows used to call "KB", what RAM is measured in)

To remove the ambiguity, the IEC introduced new binary prefixes in 1998: KiB (kibibyte, 2^10), MiB (mebibyte, 2^20), GiB (gibibyte, 2^30), TiB (tebibyte, 2^40), PiB (pebibyte, 2^50). In practice, the old labels persist everywhere except in technical documentation, and most operating systems are inconsistent: macOS uses decimal for storage, Windows uses a mix, Linux distributions vary.

This guide explains the math, the conventions, and three reliable ways to convert.

The exact formulas

Decimal (SI, used by hard drive makers, network speeds)

``` 1 KB = 1,000 B = 10^3 B 1 MB = 1,000 KB = 1,000,000 B = 10^6 B 1 GB = 1,000 MB = 1,000,000,000 B = 10^9 B 1 TB = 1,000 GB = 1,000,000,000,000 B = 10^12 B 1 PB = 1,000 TB = 10^15 B ```

Binary (IEC, used by RAM, file formats, some OSes)

``` 1 KiB = 1,024 B = 2^10 B 1 MiB = 1,024 KiB = 1,048,576 B = 2^20 B 1 GiB = 1,024 MiB = 1,073,741,824 B = 2^30 B 1 TiB = 1,024 GiB = 1,099,511,627,776 B = 2^40 B 1 PiB = 1,024 TiB = 2^50 B ```

The ratio between decimal and binary grows quickly: a "1 TB" drive is 1,000,000,000,000 bytes in marketing, but your OS may show 931 GiB of usable space after formatting and overhead. That gap widens with size β€” a "1 PB" drive is roughly 0.89 PiB.

Quick reference table

| Bytes | Decimal (SI) | Binary (IEC) | |---------:|----------------------|-------------------------| | 1,000 | 1 KB | 0.977 KiB | | 1,024 | 1.024 KB | 1 KiB | | 1,000,000| 1 MB | 0.954 MiB | | 1,048,576| 1.049 MB | 1 MiB | | 10^9 | 1 GB | 0.931 GiB | | 2^30 | 1.074 GB | 1 GiB | | 10^12 | 1 TB | 0.909 TiB | | 2^40 | 1.100 TB | 1 TiB | | 10^15 | 1 PB | 0.888 PiB |

Method 1: Use UtilBoxx's Data Storage Converter (Recommended)

The fastest, safest way to convert between B, KB, MB, GB, TB, and PB is the UtilBoxx Data Storage Converter. It supports both decimal and binary modes, lets you pick the precision, and runs entirely in your browser β€” no upload, no signup, no log of your files.

How to use it:

  1. Go to utilboxx.com/en/tools/unit/data
  2. Enter a value in any field (B, KB, MB, GB, TB, or PB)
  3. Choose decimal (SI) or binary (IEC) mode
  4. All other fields update instantly
  5. Copy the result

Why we recommend this method:

  • 100% free, no signup, no email, no ads
  • Privacy-first: nothing leaves your browser
  • Decimal and binary modes with a single toggle
  • Bidirectional conversion across all six units
  • High precision β€” no floating-point rounding surprises
  • Works on any device with a browser

If you frequently quote file sizes, drive capacities, or RAM amounts, this tool will save you from making the same 1024 vs 1000 mistake over and over.

Method 2: macOS Finder (and other OS file managers)

If you only need to know the exact byte count of a specific file, your operating system's file manager gives you the decimal answer with full precision.

On macOS Finder:

  1. Right-click any file and choose Get Info (or press Cmd+I)
  2. The size is shown in decimal units: KB, MB, GB
  3. Click the size field to flip between bytes, KB, MB, and GB
  4. The exact byte count is in parentheses

On Windows File Explorer:

  1. Right-click a file and choose Properties
  2. Size is shown in KB, MB, or GB (Windows uses a mix of binary and decimal depending on version)
  3. For exact bytes, divide KB by 1,024 only if Windows reports binary KB; modern Windows 10/11 actually reports in binary for some dialogs and decimal for others

On Linux:

  1. `ls -l file` shows exact bytes
  2. `ls -lh file` shows human-readable size (most distros use binary by default; some use decimal β€” check your `alias ls`)

This method is great when you want to know the size of a specific file or folder, but it does not help with batch conversion or unit-to-unit math.

Method 3: Python (or any language)

For programmatic conversion, a few lines of Python cover all six units. The `bit_length()` method gives you the number of bits needed to represent an integer β€” useful when sizing buffers.

```python # Decimal (SI) conversion def to_bytes(value, unit): units = {"B": 1, "KB": 1e3, "MB": 1e6, "GB": 1e9, "TB": 1e12, "PB": 1e15} return value * units[unit]

# Binary (IEC) conversion def to_bytes_binary(value, unit): units = {"B": 1, "KiB": 210, "MiB": 220, "GiB": 230, "TiB": 240, "PiB": 2*50} return value units[unit]

# bit_length of an integer n = 123456789 print(n.bit_length()) # 27 bits ```

For one-liners in a Python REPL:

```python # Convert 1 GiB to bytes 1024 1024 1024 # 1073741824

# Convert 1 TB to GiB 1_000_000_000_000 / (2**30) # 931.3225746154785

# Convert 5 PB to TiB 5 1e15 / (2*40) # 4547.473508864641 ```

In JavaScript, the same idea:

```js const GiB = 1024 ** 3; const TB_in_bytes = 1e12; console.log((TB_in_bytes / GiB).toFixed(3)); // 931.323 ```

Method 4: CLI on macOS/Linux

Most shells have built-in math, and macOS ships with a calculator that handles big numbers:

```bash # In bash, using awk awk 'BEGIN { printf "1 TB in GiB = %.3f\n", 1e12 / (2^30) }' # 1 TB in GiB = 931.323

awk 'BEGIN { printf "1 GiB in bytes = %d\n", 2^30 }' # 1 GiB in bytes = 1073741824

# macOS only: use units units "1 TB" "GiB" # 931.32257

# Linux only: numfmt is built into coreutils numfmt --to=iec --suffix=B 1000000000000 # 931G numfmt --to=si --suffix=B 1073741824 # 1.1G ```

The `numfmt` tool is particularly useful in shell scripts: it accepts numbers with optional units and reformats them, supports both decimal (--si) and binary (--iec) modes, and handles negative numbers correctly.

Common questions

Why does my "1 TB" drive show 931 GB?

Drive vendors use decimal: 1 TB = 1,000,000,000,000 bytes. Operating systems often display this in binary, which they call GB but actually means GiB. 1,000,000,000,000 bytes Γ· 1,073,741,824 bytes per GiB = 931.32 GiB. The "missing" space is the difference between decimal and binary, plus overhead from formatting, partition tables, and filesystem metadata.

Is MB bigger than MiB?

Yes. MB is decimal (1,000,000 bytes) and MiB is binary (1,048,576 bytes). MiB is about 4.86% larger than MB. The same applies to KB vs KiB, GB vs GiB, TB vs TiB.

Does RAM use binary or decimal?

RAM is sold and addressed in binary. A "16 GB" stick of RAM is 16 GiB (17,179,869,184 bytes) and reports as such to the OS. The marketing "GB" is technically incorrect by SI standards, but the convention is so entrenched that no one has tried to relabel memory as "GiB".

What about network speeds?

Network equipment has historically used decimal for bits per second (1 Mbps = 1,000,000 bits per second). Many ISPs also advertise in decimal but quote speeds in bytes per second mixed with bits, leading to the classic "I pay for 100 Mbps but I only get 12 MB/s" confusion. Divide by 8 (bits to bytes) and account for overhead, and 100 Mbps becomes roughly 11-12 MB/s. The math checks out; the units are confusing.

What's bigger, a KB or a KiB?

A KiB is bigger. 1 KiB = 1,024 B, while 1 KB = 1,000 B. The KiB (kibibyte) is 2.4% larger than the KB (kilobyte). The same pattern holds: MiB > MB, GiB > GB, TiB > TB, PiB > PB.

Why hasn't the industry standardized on one?

It has, in standards. The IEC has officially used binary prefixes (KiB, MiB, GiB) since 1998 and the SI standard explicitly says "kilo" means 1,000. But the binary prefixes have not displaced the old labels in everyday use. Apple uses decimal GB and TB consistently. Microsoft uses binary for RAM but decimal for storage. Linux tools are split. The result is permanent ambiguity, and the only fix is to know which convention you are dealing with in any given context.

Conclusion

Bytes, kilobytes, megabytes, gigabytes, terabytes, and petabytes are not interchangeable, and the decimal-vs-binary gap grows with each step up the ladder. The formulas are simple β€” divide by 1,000 for decimal, by 1,024 for binary β€” but remembering which one to use is the hard part.

For a quick answer, the UtilBoxx Data Storage Converter does the math in either mode with one click. For the size of a specific file, your OS file manager gives you the exact byte count. For batch or scripted work, Python's arithmetic or the `numfmt` CLI are unbeatable. And when in doubt, look for the trailing "i": KiB, MiB, GiB, TiB, PiB always mean binary.