OverflowError in Python — What It Means and How to Fix It
What Python's OverflowError exception means and how to resolve it.
Published October 28, 2026
OverflowError is raised when an arithmetic result is too large for the numeric type, most commonly with floats (math.exp(1000)).
What it means and why it happens
Python integers are unlimited, so it mainly affects floats and C-based math functions.
Read the full message: it names the file and line where the problem was detected, which is the best place to start.
What you see
run the code
OverflowError: (34, 'Numerical result out of range')
Practical examples
Code that triggers it
import math
math.exp(1000)The fix
import math
try:
math.exp(1000)
except OverflowError:
result = float('inf')Use big integers
print(2 ** 10000) # ints do not overflowCommon mistakes
- Assuming ints overflow like in C.
- Not bounding inputs to exp/pow.
- Silent inf values in NumPy.
Key takeaways
- OverflowError: OverflowError is raised when an arithmetic result is too large for the numeric type, most commonly with floats (math.exp(1000)).
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
Do ints overflow?
No, Python ints have arbitrary precision.
How do I find which line caused OverflowError?
The error message and stack trace show the file and line; start there and work backwards.