Skip to main content
i32 is a primitive, fixed-size data type in Rust representing a 32-bit signed integer. It occupies exactly 4 bytes of memory and encodes values using two’s complement representation, allowing it to store both positive and negative whole numbers.

Technical Specifications

  • Memory Size: 32 bits (4 bytes)
  • Minimum Value (i32::MIN): -2,147,483,648 (231-2^{31})
  • Maximum Value (i32::MAX): 2,147,483,647 (23112^{31} - 1)
  • Type Inference: The Rust compiler (rustc) defaults to i32 for any unannotated integer literal unless constrained by the surrounding type context.

Syntax and Instantiation

Values of type i32 can be declared using explicit type annotation, literal suffixes, or implicit type inference.
i32 supports standard numeric literal prefixes for different bases:

Overflow Behavior

Rust handles i32 arithmetic overflow differently depending on the compilation profile:
  • Debug mode (cargo build): Integer operations that exceed the i32 bounds trigger a runtime panic.
  • Release mode (cargo build --release): The compiler performs standard two’s complement wrapping. Values wrap through the boundary rather than stopping at it (e.g., i32::MAX + 1 results in i32::MIN, and i32::MAX + 2 results in i32::MIN + 1), without panicking.
To explicitly control overflow behavior regardless of the build profile, the i32 primitive provides standard library methods:

Memory Layout and Casting

i32 implements the Copy trait, meaning reassignments perform a bitwise duplication of the value rather than moving ownership. The memory location of an i32 is determined by its allocation context: it is stored on the stack when declared as a local variable, but resides on the heap when owned by a heap-allocated collection or smart pointer (e.g., Vec<i32> or Box<i32>). Casting i32 to other numeric types requires the explicit as keyword. Casting to a smaller integer type (e.g., i16 or i8) truncates the higher-order bits.
Tired of Poor Rust Skills? Fix That With Deep Grasping!Learn More