Space Complexity

Calculate Space Complexity instantly with the exact formula and a worked example.

Space Complexity

Number of elements n
Bytes per element (int32 = 4, int64/double = 8)bytes
Memory, MiB
3.8147MiB
Excludes container overhead and alignmentCalculate Space Complexity instantly with the exact formula and a worked example.
Bytes
4000000
In KiB
3906.3KiB
In GiB
0.004GiB

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

  1. Enter number of elements n and bytes per element (int32 = 4, int64/double = 8) — each field above is adjustable with a slider.
  2. Memory, MiB (MiB) is calculated automatically as you type.
  3. Check the worked example below to see the formula applied to real numbers.
  4. Copy the result or bookmark this calculator.

Related calculators

FAQ

Why is 4,000,000 bytes 3.81 MB and not 4?
The calculator divides by 1,048,576 (2²⁰), i.e. binary megabytes. In decimal units (1 MB = 10⁶ bytes) it would be 4 MB.
What does O(1) space mean?
The extra memory does not depend on input size — a few counters or pointers, for example. Here that corresponds to a fixed n.
How much memory does a 10,000 × 10,000 matrix of doubles need?
Enter n = 100,000,000 and b = 8: 800,000,000 bytes ≈ 762.9 MB ≈ 0.745 GB.

More calculators in this category

Explore related free tools

Min Spanning Tree (Prim/Kruskal)Bellman-FordFloyd-WarshallKnapsack DPEdit Distance (Levenshtein)Jaro-Winkler DistanceCosine SimilarityTF-IDFSilhouette ScoreCable Length (CAT5e/6)CSS Cubic BezierCSS Border Radius