Space Complexity
Calculate Space Complexity instantly with the exact formula and a worked example.
Space Complexity
Big-O tells you how memory grows; this calculator tells you how much it actually is — bytes, KB, MB and GB for n elements of a given size.
How the calculation works
Space complexity describes how an algorithm's memory use scales with input size. O(n) captures the growth rate but not the number of megabytes. Here the payload is computed directly: memory = n × b, where n is the number of elements and b is the size of one element in bytes.
Common values for b: 1 byte for char/uint8, 4 bytes for int32 and float, 8 bytes for int64, double and a pointer on a 64-bit platform. The result uses binary units: 1 KB = 1,024 bytes, 1 MB = 2²⁰ = 1,048,576 bytes and 1 GB = 2³⁰ bytes — strictly speaking KiB, MiB and GiB under IEC 80000-13.
For structures with other complexities, plug the real element count into n: n² for an n×n matrix, vertices plus edges for an adjacency list. Container overhead and alignment padding are not included, as the result note reminds you.
Worked example
An array of 1,000,000 int32 values (4 bytes each): 1,000,000 × 4 = 4,000,000 bytes = 3,906.3 KB ≈ 3.81 MB ≈ 0.004 GB. Store the same values as int64 or double (8 bytes) and you get 8,000,000 bytes ≈ 7.63 MB — exactly twice as much.
Things to keep in mind
- Boxed values cost far more: in CPython each list slot is an 8-byte pointer plus a separate int object (about 28 bytes for small numbers).
- Dynamic arrays (std::vector, ArrayList, Python list) keep spare capacity, and hash tables leave buckets empty on purpose — budget extra headroom.
- Recursive algorithms use stack space too: recursion depth × frame size counts toward space complexity.
- Distinguish auxiliary space (extra memory beyond the input) from total space: merge sort needs O(n) auxiliary memory, heapsort O(1).
More about: Space Complexity
What it calculates
The “Space Complexity” calculator computes Memory, MiB in MiB from 2 parameters: number of elements n, bytes per element (int32 = 4, int64/double = 8) (bytes).
Standard IT calculations for developers and sysadmins.
Example calculation
With parameters Number of elements n = 1,000,000, Bytes per element (int32 = 4, int64/double = 8) = 4 bytes the result is 3.81 MiB (Excludes container overhead and alignment).
How to use
- Enter number of elements n and bytes per element (int32 = 4, int64/double = 8) — each field above is adjustable with a slider.
- Memory, MiB (MiB) is calculated automatically as you type.
- Check the worked example below to see the formula applied to real numbers.
- Copy the result or bookmark this calculator.
Related calculators
FAQ
Why is 4,000,000 bytes 3.81 MB and not 4?
What does O(1) space mean?
How much memory does a 10,000 × 10,000 matrix of doubles need?
More calculators in this category
Explore related free tools