What does RecursionError: maximum recursion depth exceeded mean in Python?

Updated October 2026 · How we answer

Short answerThis error means a function called itself too many times without stopping. The usual cause is a missing or unreachable base case in a recursive function.

What is happening

Python limits how deep function calls can nest, and the default limit is commonly around 1000 frames. When a recursive function keeps calling itself and never reaches its stopping condition, the call stack fills up and Python raises RecursionError to protect the program.

The traceback will show the same function repeating many times. That repetition is the clue. Look at the function's stopping condition and check whether each call moves closer to it.

  • Look for a repeated function name in the traceback
  • Check that the input changes on each call
  • Confirm the base case can actually be reached

How to fix it

Make sure the base case runs for every possible input, including empty values and zero. Then check that each recursive call passes a smaller or different input. A common bug is decreasing the wrong variable or returning the same argument.

If the recursion depth is legitimately large, rewrite the function with a loop and an explicit stack. Raising the recursion limit with sys.setrecursionlimit can hide the problem and may crash the interpreter, so use it only with care.

Tail recursion is not optimized in standard CPython, so rewriting the logic as a loop is often the cleanest fix. Test with a small input first to confirm the stopping condition works.

Common mistakes

  • Raising the recursion limit without finding the missing base case.
  • Forgetting that an empty list or zero input can skip the intended stopping point.
From our shopsCaseMorph: Type an idea, see a custom phone case in seconds, then print a one-of-one.