Python handles very large integers natively: the built-in int type has arbitrary precision, so it grows as needed and is limited only by available memory. There is no overflow and no separate "long" type, so 2**1000 or factorial(500) simply works. These Python big integers are stored as arrays of 30-bit digits, which makes them slower than machine integers but always exact.
This article covers Python 3.13 and 3.14. It explains how CPython stores large values, what they cost in memory and time, and the one safety limit you can hit when converting huge integers to text.
In Python 3 every integer is an int, and an int never overflows. In Python 2, int and long were separate types, but they were merged in Python 3.
Arithmetic on these values is always exact. Compare that with fixed-width integers in C, Java or Go, where int64 wraps around once it passes 9,223,372,036,854,775,807. Python never wraps.
For readability you can write large literals with underscores, and you can use bit_length() to see how large a value is in bits:
CPython stores an int as a sign plus a sequence of "digits", each holding 30 bits on 64-bit builds (the digit is a 32-bit unsigned integer with 30 bits used). You can inspect this with sys.int_info:
Memory grows by 4 bytes for every extra 30 bits on top of a fixed object header, so a 1,000-bit number takes roughly 160 bytes. The exact sizes can vary by build and Python version, so treat sys.getsizeof as the source of truth on your machine.
Two implementation details are worth knowing:
==, never is.Big-integer arithmetic costs more as numbers grow. Addition and subtraction are linear in the number of digits. Multiplication uses the schoolbook method for small sizes and Karatsuba multiplication for large ones, which is faster than quadratic. Division and conversion to a decimal string are quadratic or worse in the general case.
| Operation | Rough cost for n digits |
|---|---|
| Addition, subtraction | Linear |
| Multiplication | Between linear and quadratic (Karatsuba for large values) |
| Division, modulo | Quadratic |
str(n) and int(s) in base 10 | Quadratic in CPython |
Bit shifts, &, |, ^ | Linear |
For everyday numbers the overhead is negligible. It matters in tight loops, for example computing very large Fibonacci or factorial values, where the time is dominated by the size of the operands.
Cryptography-style code often needs a ** b % m for huge b. Do not compute the power first. The three-argument pow uses fast modular exponentiation and keeps every intermediate value small:
The first call finishes instantly. Writing 7 ** (10**18) % 1_000_000_007 would try to build a number with hundreds of quadrillions of digits and never finish.
Since Python 3.11 (and backported to supported 3.7 to 3.10 security releases) CPython limits integer-to-string and string-to-integer conversions in bases that are not powers of two. The default is 4,300 digits. It exists because the quadratic conversion cost made a short malicious input a denial-of-service risk.
The limit applies to int(s), str(n), repr(n) and f-strings in base 10. It does not apply to hexadecimal, octal or binary, so hex(n) always works. You can change it in three ways:
sys.set_int_max_str_digits(0) in your program (0 disables the limit).PYTHONINTMAXSTRDIGITS.-X int_max_str_digits=N.Raise the limit only for trusted input. If you parse numbers from users, keep the default and handle the ValueError.
Python integers are exact but slow compared with fixed-width ones. Use other tools in these cases:
int64 and do overflow silently. Use dtype=object for exact values, at the cost of speed.gmpy2 package wraps the GMP library and is much faster than the built-in type.int is the wrong type; see Fraction and Decimal in the standard library.There is no maximum for int. The practical limit is available memory. sys.maxsize is only the largest value a C Py_ssize_t can hold, which is used for container sizes and indexes.
You are hitting the 4,300-digit conversion limit added in Python 3.11. Use sys.set_int_max_str_digits() for trusted data, or split and process the input differently.
Yes, once a value exceeds one 30-bit digit and especially for very large values. For typical program values the difference is not noticeable.
Create the array with dtype=object so each element is a Python int. Fixed-width dtypes overflow without raising an error.
Python's int has arbitrary precision, stored as 30-bit digits, so large values are exact and never overflow. Costs grow with size, multiplication uses Karatsuba, and base-10 conversion is limited to 4,300 digits by default since Python 3.11. Use pow(a, b, m) for modular exponentiation and reach for gmpy2 only when profiling shows big-integer arithmetic is your bottleneck.