# Space Complexity

> How much extra memory a task needs. It grows with the input.

**Field:** Software Development  
**Category:** Algorithms & Data Structures  
**Also known as:** Memory Complexity

## Think of it like

Think of it like a recipe. A bigger cake needs more bowls.

## Definition

Space complexity is how much extra memory an algorithm needs as its input grows. Like time complexity, it is written in Big O. Sorting a list in place may need O(1) extra memory. Making a full copy of the list needs O(n). Often you can trade one for the other: use more memory to save time, or the reverse.

## Example

Jack's first version copied a 2 GB file into memory to count its lines. Reading it one line at a time cut the memory to a few kilobytes.

## Why it matters

Memory runs out before time does on phones, small servers and huge data sets.

## Common mistake

Counting only time. A fast algorithm that needs ten times the memory can crash on real data.

## Three principles

- **Extra memory.** Beyond the input itself.
- **Written in Big O.** O(1), O(n) and so on.
- **Trade with time.** More memory, fewer steps.

## Related terms

- [Big O Notation](https://learn.benibix.com/term/development/big-o-notation)
- [Time Complexity](https://learn.benibix.com/term/development/time-complexity)
- [Memoization](https://learn.benibix.com/term/development/memoization)
- [Algorithm](https://learn.benibix.com/term/development/algorithm)

## Told apart from

- [Time vs Space Complexity](https://learn.benibix.com/compare/time-vs-space-complexity): Time complexity counts steps. Space complexity counts memory. Both say how the cost grows as the input grows, and a faster way often needs more memory.

---

Source: https://learn.benibix.com/term/development/space-complexity
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
