Integer Limits

The Minimum Int Value in C++

Learn the minimum int value in C++: INT_MIN from climits, usually -2,147,483,648 on 32-bit systems. See how to get it in code and avoid overflow traps.

On this page
  1. The short answer
  2. Why the number is -2,147,483,648
  3. Get the value in code
  4. Check the width of int
  5. Watch for overflow below INT_MIN
  6. Use INT_MIN as a starting maximum
  7. Unsigned types start at zero
  8. Values from text
  9. Summary

The short answer

On most current systems, the smallest value an int can hold in C++ is -2,147,483,648. The <climits> header names it INT_MIN, and the <limits> header gives the same number through std::numeric_limits<int>::min(). The exact value depends on how many bits int uses on your platform, so check it there rather than hard-coding the number.

Why the number is -2,147,483,648

The C++ standard does not fix the size of int. It only requires a range that covers at least -32,767 to 32,767. Most desktop and server platforms use a 32-bit int, which gives a lower end of -2^31 and an upper end of 2^31 - 1. In plain numbers, that is -2,147,483,648 to 2,147,483,647.

The other built-in integer types have their own limits, which are listed under primitive data types in c.

Get the value in code

Using <climits>:

#include <climits>
#include <iostream>

int main() {
    std::cout << "INT_MIN: " << INT_MIN << '\n';
}

On a platform with a 32-bit int, this prints INT_MIN: -2147483648. The output has no thousands separators.

Using <limits>:

#include <iostream>
#include <limits>

int main() {
    std::cout << std::numeric_limits<int>::min() << '\n';
}

For integer types, min() and lowest() return the same value. For floating-point types they do not. std::numeric_limits<double>::min() is the smallest positive value, not the most negative one, so use lowest() when you need the most negative double.

Check the width of int

sizeof reports a size in bytes, and CHAR_BIT from <climits> gives the number of bits in a byte. Multiplying them gives the width of int on your system:

#include <climits>
#include <iostream>

int main() {
    std::cout << "int has " << sizeof(int) * CHAR_BIT << " bits\n";
}

On most desktop systems this prints 32. For more on how sizeof works, read the sizeof function in c guide.

Watch for overflow below INT_MIN

Several common operations go below INT_MIN. Signed overflow is undefined behavior in C++, so the result of such an operation cannot be relied on.

  • Negating INT_MIN. -INT_MIN would be 2,147,483,648, which does not fit in an int. The same problem affects std::abs(INT_MIN).
  • Subtracting from INT_MIN. INT_MIN - 1 is below the range.
  • Decrementing at INT_MIN. Running --x on a variable that holds INT_MIN overflows in the same way.

Typing the number by hand is a trap too. Prefer INT_MIN to writing -2147483648 yourself. The digits are easy to get wrong, and 2147483648 does not fit in a 32-bit int on its own.

Use INT_MIN as a starting maximum

A common pattern is to start a search for the largest value with INT_MIN:

#include <climits>
#include <vector>

int largest(const std::vector<int>& values) {
    int best = INT_MIN;
    for (int v : values) {
        if (v > best) {
            best = v;
        }
    }
    return best;
}

This works for any non-empty vector. Every element is at least INT_MIN, so the loop ends with the largest element, and if every element is INT_MIN the answer is INT_MIN anyway. An empty vector also returns INT_MIN, which looks like a real answer, so check for empty input first.

Unsigned types start at zero

An unsigned int has no negative values, so its minimum is 0. The difference between signed and unsigned types is covered in signed vs unsigned in c.

Values from text

Numbers read from text can fall outside the int range, just as computed values can. std::stoi throws std::out_of_range when the text is too large or too small, so you can catch that and report the problem. For the other ways to convert text, see c convert string to int.

Summary

The minimum value of an int in C++ is INT_MIN from <climits>, which is usually -2,147,483,648 on a 32-bit int. std::numeric_limits<int>::min() returns the same value. Keep the overflow traps in mind: negating, subtracting from, or decrementing past INT_MIN are all undefined behavior.

Keep exploring

Guides from other topics

All topics →

Shift Operators in C++

Learn how the << and >> shift operators work in C++, with binary examples, compound forms, precedence traps, undefined cases, and safe ways to use them.

C++ While Loop Syntax

Learn the C++ while loop syntax, how the condition is checked, and how to avoid infinite loops, with step-by-step examples you can compile and run.

While Loops 4 min read

How to Use goto in C++

Learn how to use goto in C++: write a label and jump to it, see forward and backward examples, avoid compile errors, and pick safer alternatives.

goto 5 min read