October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
C++

Integer (int): Meaning, Ranges, Overflow, and Choosing the Right Type

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An integer is a number with no fractional part: …, −2, −1, 0, 1, 2, …. In programming, an integer type stores such values within a finite range (unless the language provides arbitrary precision). int is a language-specific type name—not a universal 32-bit format. Its size, range, conversions, and overflow behavior depend on the language and, in C and C++, the target implementation.

Integer values, literals, and types

-7, 0, 42, and 2_000_000 (where digit separators are supported) are integer values written as literals. A literal is source-code notation; its default type is chosen by the language. A variable’s integer data type determines what values it can store and how operations behave.

“Whole number” is useful for beginners, but “number with no fractional part” is more precise: integers include negative values and zero. An integer type cannot directly represent 3.14; converting a fraction to an integer requires a language-defined conversion such as truncation or rounding.

What does int mean?

In C, C++, Java, C#, and related languages, int is commonly a built-in type or keyword. The same spelling does not promise the same representation.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
int count = 42;

JavaScript has no ordinary separate int type: 42 is normally a Number. Python code can simply write count = 42 without declaring a fixed-width type. Always check the language specification and implementation before relying on a range.

Signed and unsigned integers

A signed type represents negative and nonnegative values. An unsigned type represents zero and positive values only. For an N-bit two’s-complement signed representation, the usual range is −2N−1 through 2N−1−1; an N-bit unsigned representation ranges from 0 through 2N−1. These relationships are described for fixed-width types by The Open Group’s stdint.h specification.

Representation 8-bit range
Signed −128 to 127
Unsigned 0 to 255

Unsigned is not automatically safer. Subtracting from zero can wrap to a very large value, and mixed signed/unsigned comparisons in C and C++ can produce surprising results.

How wide is an int?

C and C++

C and C++ leave the width of int implementation-dependent within minimum requirements. It is commonly 32 bits on modern desktop and server systems, but narrower implementations exist. See the Microsoft C documentation, GNU C integer overview, and C++ fundamental-type reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Inspect the implementation instead of assuming four bytes:

#include <limits.h>
#include <stdio.h>

printf("%zu\n", sizeof(int));
printf("%d through %d\n", INT_MIN, INT_MAX);

When a file, protocol, or binary layout requires an exact width, use available fixed-width types such as int32_t or uint64_t from <stdint.h>.

Java and C#

Java int is always a signed 32-bit value from −2,147,483,648 through 2,147,483,647; long is signed 64-bit. The Java documentation lists these widths and ranges at Oracle’s data-types tutorial.

C# int is an alias for signed System.Int32, with the same 32-bit range. The language specification documents integral types and overflow contexts at Microsoft Learn.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

JavaScript

JavaScript’s ordinary Number uses IEEE-754 double precision. Integer values are exact only through ±(253−1), or 9,007,199,254,740,991; beyond that, distinct integers can become indistinguishable. See MDN’s Number reference. BigInt provides arbitrary-magnitude integers, but it is a separate type and cannot be mixed implicitly with Number arithmetic (MDN BigInt).

Common 32-bit ranges

These exact values apply to Java and C# int, and to any 32-bit representation with the stated signedness:

Type Minimum Maximum
Signed 32-bit −2,147,483,648 2,147,483,647
Unsigned 32-bit 0 4,294,967,295

Do not apply this table automatically to C or C++ int; query the implementation.

Overflow and underflow

Overflow occurs when a result exceeds the type’s maximum; underflow occurs when it falls below its minimum. For example, 2,147,483,647 + 1 cannot be represented by a signed 32-bit integer.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • C: unsigned arithmetic is modulo 2N; signed overflow is undefined behavior under ordinary language rules (GNU overflow guidance).
  • C++: signed overflow is not portable to rely on; unsigned arithmetic has modular behavior. Consult the applicable standard and compiler mode (cppreference).
  • C#: checked contexts detect integral overflow, while unchecked contexts permit the unchecked result; project settings can affect defaults.
  • Java: fixed-width integer operations wrap according to Java’s two’s-complement rules.
  • JavaScript: precision loss in Number is often the main hazard; use BigInt for exact larger integers.

Check before an operation, not after it. In C, for example:

#include <limits.h>
if (a > INT_MAX - b) {
    /* addition would overflow */
}

A cast does not make an already-overflowing calculation safe.

Division, remainder, and conversions

Integer division

In C, C++, Java, and C#, dividing integer operands produces an integer result; a fractional part is discarded. For example, 5 / 2 is 2. These languages truncate integer division toward zero, so negative cases such as -5 / 2 produce -2; the remainder’s sign follows language rules. JavaScript differs: 5 / 2 is 2.5, while 5n / 2n is 2n (MDN language overview).

Conversions and promotions

Narrowing a wide value can discard information. Signed-to-unsigned conversion follows each language’s rules and may produce a large nonnegative value. In C, small integer types are promoted before arithmetic, and mixed signed/unsigned operands can change comparisons:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
int a = -1;
unsigned int b = 1;
if (a < b) {
    /* may surprise you */
}

GNU explains promotions and mixed arithmetic at Integer Arithmetic.

Literals, bases, and parsing text

C-like languages support decimal and hexadecimal notation, and some support binary literals by version:

int decimal = 42;
int hexadecimal = 0x2A;
int binary = 0b101010;  /* support varies */

Suffixes such as u, L, and LL influence literal type selection in C and C++. A literal can be too large for its intended type before assignment. Parsing is a different operation: "123" is text, whereas 123 is a numeric value. A parser must define the radix, whitespace and sign handling, invalid characters, empty input, range checking, and its failure signal (exception, error result, sentinel, or truncation).

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How integers are represented

Integers are stored as bit patterns. Bit width determines the number of available patterns; signed two’s-complement is widespread. The same bits can represent different values when interpreted as signed or unsigned (GNU’s representation explanation).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Decimal, hexadecimal, octal, and binary are source notations, not different kinds of integer. Endianness describes byte order in memory or serialized data; it does not change the mathematical value.

Choosing an integer type

Requirement Usually consider
Ordinary bounded counter or loop The language’s conventional integer, often int
Exact file, protocol, or binary width int32_t, uint64_t, or the language’s fixed-width equivalent
Values beyond signed 32-bit range A documented wider type such as long, long long, long in Java, or a big-integer type
Array/object sizes in C or C++ size_t or the API-specified size type
Arbitrarily large exact values Big-integer facility, such as JavaScript BigInt
Fractions or currency amounts Decimal arithmetic or a documented smallest-unit design, not a casual int choice
Identifiers with leading zeroes or arbitrary length A string or dedicated identifier type

Base the decision on required bounds, whether negatives are meaningful, portability, interoperability, overflow policy, memory and performance constraints, and API compatibility. Unsigned types can increase nonnegative range but also complicate subtraction and comparisons.

Where integer bugs appear

  • Off-by-one errors at minimum or maximum bounds.
  • Signed overflow or unsigned wraparound.
  • Narrowing conversions and mixed signed/unsigned comparisons.
  • Assuming sizeof(int) == 4 across C and C++ targets.
  • Treating JavaScript Number as an arbitrary-precision integer or mixing Number and BigInt.
  • Unexpected truncation in division, especially with negative operands.
  • Malformed parsing that becomes zero, a partial value, or an unchecked sentinel.
  • Multiplication overflow before division: a * b / c can overflow in a * b even when the final result fits.
  • Serialization mismatches between 32-bit and 64-bit fields.

Testing and defensive practice

  • Test zero, one, negative values, both bounds, and one value beyond each bound.
  • Test empty and malformed input, mixed-type expressions, and exact serialized boundaries.
  • Run portability tests on 32-bit and 64-bit targets when relevant.
  • Query limits from the language or library instead of hard-coding them.
  • Enable compiler warnings and static analysis; use checked arithmetic or safe-arithmetic libraries for security-sensitive code.
  • Test debug and optimized C/C++ builds, where undefined behavior can produce different results.

NIST classifies integer overflow among recurring software defects involving range, signedness, and type selection (NIST publication).

Quick answers

Is int always 32-bit?

No. It is guaranteed 32-bit in Java and C#, commonly 32-bit but implementation-dependent in C and C++, and not the ordinary integer type in JavaScript.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can an integer store decimals?

No. A fractional value must use a fractional type or an explicit conversion.

What should I use for a protocol field?

Use an explicitly sized integer with documented signedness and byte order.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.