# Base Case

> The simple case where a function that calls itself stops.

**Field:** Software Development  
**Category:** Algorithms & Data Structures  
**Also known as:** Base Case (Recursion), Stopping Condition, Terminating Case

## Think of it like

It is like the bottom step of a staircase. Once you reach it, you stop going down.

## Definition

A base case is the simplest input a recursive function answers at once, without calling itself again. Every other call makes the problem a bit smaller, until it reaches the base case. Then the answers pass back up. Without a base case, the calls never stop. The program runs out of stack space and crashes.

## Example

A countdown function prints n, then calls itself with n minus 1. When n is 0, the base case prints Go! and stops.

## Example code

```python
def countdown(n):
    if n == 0:        # base case
        print("Go!")
        return
    print(n)
    countdown(n - 1)

countdown(3)  # 3 2 1 Go!
```

When n reaches 0, the function stops calling itself.

## Why it matters

It is what makes recursion end. Every recursive function needs one that the input is sure to reach.

## Common mistake

Writing a base case the input can skip past, like n == 0 when n goes down by 2 from 5. The calls never stop.

## Three principles

- **Answer at once.** No more self-calls.
- **Must be reached.** Each call moves toward it.
- **Stops the stack.** Without it, the program crashes.

## Related terms

- [Recursion](https://learn.benibix.com/term/development/recursion)
- [Divide and Conquer](https://learn.benibix.com/term/development/divide-and-conquer)
- [Stack Memory](https://learn.benibix.com/term/development/stack-memory)
- [Backtracking](https://learn.benibix.com/term/development/backtracking)
- [Dynamic Programming](https://learn.benibix.com/term/development/dynamic-programming)

## Taught in

- [Recursion in Python](https://learn.benibix.com/learn/development-concepts/recursion-in-python): Programming Basics, 14/18

![Two panels. On the left, a countdown calls itself with 3, then 2, then 1, then 0, where a box marked base case says stop, and the calls return. On the right, a small maze tree: a path tries left, hits a dead end, steps back, tries right and reaches the goal.](https://learn.benibix.com/diagrams/dev7-base-case-backtracking.svg)

---

Source: https://learn.benibix.com/term/development/base-case
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.
