File Size Formula (KB, MB and GB to Bytes)

Technology Formula • Published on November 10, 2026 • Last updated November 10, 2026

Calculator: Sample File Library & Dummy File Generator

Mathematical Equation

$$S = n \times B^{k}$$

Variable Definitions

S

File size in bytes

n

Number of units you want to convert (for example 5 for 5 MB)

B

Base of the unit system: 1,024 for the binary standard, 1,000 for the decimal standard

k

Unit power: 1 for KB, 2 for MB, 3 for GB, 4 for TB

Detailed Explanation

In-Depth Guide

Key Concept

Upload limits, storage quotas and bandwidth plans are all written in kilobytes, megabytes and gigabytes, but a computer only counts bytes. This formula converts a size written in units into the exact number of bytes.

The catch is that two systems are in use: the binary standard, where each step is 1,024 times larger, and the decimal standard, where each step is 1,000 times larger. Operating systems, PHP and many frameworks use binary steps, while many storage vendors and some APIs use decimal steps, so the same 5 MB label can mean two different byte counts.

How to Calculate: Step-by-Step

1. Write down the size you need, for example 5 MB. 2. Decide which standard your system uses: binary (B = 1,024) or decimal (B = 1,000). 3. Set the power k: 1 for KB, 2 for MB, 3 for GB. 4. Raise the base to that power: B to the power k. 5. Multiply by the number of units n to get the size in bytes. 6. To go the other way, divide the byte count by B to the power k.

Worked Calculation Example

Convert a 5 MB upload limit to bytes: - Binary standard: 5 × 1,024² = 5 × 1,048,576 = 5,242,880 bytes - Decimal standard: 5 × 1,000² = 5 × 1,000,000 = 5,000,000 bytes - The two results differ by 242,880 bytes (about 4.9 percent), so a file that passes one limit can fail the other. - For boundary testing, also try one byte below and one byte above the limit: 5,242,879 and 5,242,881 bytes.

Calculate File Size Formula (KB, MB and GB to Bytes) Instantly

Skip manual arithmetic — calculate your own values with our free interactive tool.

Open Sample File Library & Dummy File Generator

Common Use Cases

  • Setting and verifying upload size limits in web forms and APIs
  • Converting storage quotas and bandwidth plans into exact bytes
  • Generating test files that sit exactly on, below and above a size limit

Frequently Asked Questions

Computers address memory in powers of two, so operating systems traditionally count 1 KB as 1,024 bytes and 1 MB as 1,024 × 1,024 bytes. Storage vendors often use powers of ten instead. The IEC names the binary units kibibyte (KiB) and mebibyte (MiB) to remove the ambiguity.

Settings such as upload_max_filesize in PHP and client_max_body_size in nginx use binary multiples, so 5M means 5 × 1,048,576 bytes. Always confirm in your own stack by testing a file at the limit and one byte above it.

Use the Sample File Library. It generates valid PDF, image, document and data files padded to an exact byte count in either standard, and its limit pack gives you files at the limit minus 1 byte, exactly the limit and the limit plus 1 byte.

What do you need to work out next?

Search 276+ free tools by name, or pick a category below. Every one runs instantly in your browser — no signup, nothing to install.

More Developer Tools
AI ADVISOR & COACH

Ask AI Advisor

Ask AI