← homeProgramming (Програмування)

What is integer overflow?

You have a counter that can only count up to a certain number. For example, a pocket calculator that shows a maximum of 999. If you try to add 1 to 999, it will not be able to display 1000 - the digits will simply "ov...

Table of contentsClick link to navigate to the desired location
This content has been automatically translated from Ukrainian.
You have a counter that can only count up to a certain number. For example, a pocket calculator that shows a maximum of 999. If you try to add 1 to 999, it will not be able to display 1000 - the digits will simply "overflow" and the calculator will show something completely different, like 000.
In programming, this effect is called integer overflow.
It occurs when a number exceeds the maximum value that the chosen variable type can hold.
For example, if an int variable can hold numbers up to 2,147,483,647, then adding 1 will make its value… negative!

Why 2,147,483,647 is the "ceiling" for a 32-bit number

In a computer, numbers are stored in binary form (that is, as a sequence of zeros and ones).
"32-bit" means that 32 cells are allocated for storing a number, and each can be either 0 or 1.
But if the number is signed, then one of these cells is reserved for the sign:
  • 0 in the first bit — the number is positive,
  • 1 in the first bit — the number is negative.
So instead of 32 bits for the magnitude of the number, only 31 bits remain.
Maximum value
When all 31 bits (except the sign) are filled with ones, we get the largest possible positive number:
1111111111111111111111111111111 (31 ones)
In decimal, this is exactly 2,147,483,647.
In hexadecimal (hex) form, it is written as 0x7FFFFFFF:
  • 7 is binary 0111 (that is, sign 0 + three ones),
  • F is binary 1111 (four ones),
  • and so on to the end.
Because of this, very strange bugs sometimes occur in programs, and there have even been serious accidents in history due to overflow. There are even memes about the integer overflow error, but that's not certain.

🔥 More posts

All posts
What is vibe coding?
Jul 25, '25 21:51

What is vibe coding?

Vibe coding is a state where you don't follow strict programming rules, but simply catch the mood...

What is a brain stack?
Jul 28, '25 19:37

What is a brain stack?

The brain is not just a sponge of neurons, but a system of layers, each of which performs its own...

What is a HAR file (HTTP Archive)?
Programming (Програмування)Aug 25, '25 18:23

What is a HAR file (HTTP Archive)?

HAR file (HTTP Archive) is a special file format .har that stores the log of a web browser's inte...

What is exponential growth?
Sep 16, '25 18:57

What is exponential growth?

Exponential growth is the process where a quantity increases in a geometric progression. In other...

What is factorial complexity?
Programming (Програмування)Sep 16, '25 19:03

What is factorial complexity?

Factorial complexity is a situation where the number of options or combinations grows like the fa...

What is NP-complexity?
Programming (Програмування)Sep 16, '25 19:31

What is NP-complexity?

NP-completeness is a class of problems for which it is very difficult to find a solution, but eas...