Definition
An integer overflow is a computing error that occurs when a calculation exceeds the maximum capacity of the memory container assigned to hold that number. The moment it surpasses this limit, the value abruptly wraps around or turns into an unexpected value, often a massive negative number or zero.
Why a Car Odometer Rolls from 9999 to 0000
Picture an analog car odometer tracking distance traveled. If it only has four dials, the highest number it can display is 9999.
If you drive just one more mile, the odometer cannot show 10000. Because there is no physical slot for a fifth digit, the leading 1 vanishes into thin air, and the display resets right back to 0000.
Computers work the exact same way under the hood. When a computer stores a number, it predetermines the size of its memory bucket. It uses a fixed number of bits—tiny slots holding either 0 or 1—such as 8, 32, or 64 bits. When all those slots are completely filled with 1s and you add 1 more, the carry digit spills over, and the computer simply discards that extra leading bit.
Why Does It Suddenly Turn Negative?
Even more common—and far more dangerous—than resetting to zero is when a positive number suddenly flips into a massive negative number.
To handle both positive and negative values, computers typically reserve the leftmost bit as a 'sign bit.' If this bit is 0, the number is positive; if it is 1, it represents a negative number.
For example, the largest positive number a standard signed 32-bit integer can hold is 2,147,483,647 (roughly 2.14 billion). If you add 1 to it, the binary math flips that leftmost sign bit from 0 to 1. Because computers use a system called two's complement, turning on that sign bit means the computer now interprets the value as negative 2,147,483,648.
This is why bizarre bugs happen in games: boost a character's health past the cap and they suddenly drop dead, or deposit money into an account only to end up billions in debt.
Overflow Incidents That Shook the Real World
This phenomenon is far from theoretical trivia. It has triggered high-profile incidents that disrupted major services and made history.
The most famous pop-culture example is YouTube's 'Gangnam Style' view count. YouTube originally stored video views using a 32-bit signed integer, with a maximum capacity of about 2.14 billion views. As Psy's mega-hit video soared toward that limit, YouTube engineers took action months beforehand by upgrading the view counter to a 64-bit integer, expanding the ceiling to over 9 quintillion. YouTube playfully shared the story in December 2014, making it a legend among developers.
Other incidents turned catastrophic. In 1996, the European Space Agency's $370 million Ariane 5 rocket disintegrated just 40 seconds after liftoff. An internal velocity measurement (a 64-bit floating-point number) overflowed when converted into a 16-bit integer. The overflow shut down the inertial reference system, and the flight computer misinterpreted diagnostic error logs as active flight data, throwing the rocket completely off course.
Common misconceptions
When a number exceeds the container's capacity, the computer safely stops and displays an error message.
In languages like C and C++, unsigned integers wrap around silently and signed integer overflows cause undefined behavior with no warning at all. This makes such bugs notoriously hard to detect. In contrast, Swift stops the program when an overflow occurs, while Rust halts execution in debug builds but wraps around by default in release builds.
Where you meet it
YouTube upgrading its view counter to a 64-bit integer before 'Gangnam Style' hit the 2.14-billion limit.
A video game bug where collecting too much gold flips your balance into zero or an enormous debt.
The 1996 Ariane 5 rocket launch failure caused by converting a 64-bit float into an overflowing 16-bit integer.
In one sentence
An integer overflow occurs when a number exceeds the maximum limit of its allocated memory, causing the value to wrap around into an unintended number, often a massive negative value or zero.