Skip to main content
In Go, int is a built-in, signed integer data type whose memory footprint is architecture-dependent. It resolves to 32 bits (4 bytes) on 32-bit systems and 64 bits (8 bytes) on 64-bit systems.

Technical Specifications

  • Zero Value: 0
  • Size: Evaluated via unsafe.Sizeof(int(0)), yielding 4 or 8 depending on the target compilation architecture (GOARCH).
  • Range (32-bit): -2³¹ to 2³¹-1 (-2,147,483,648 to 2,147,483,647)
  • Range (64-bit): -2⁶³ to 2⁶³-1 (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)

Syntax and Type Inference

When declaring an untyped integer literal, the Go compiler automatically infers the underlying type as int.
// Explicit declaration
var a int = 10

// Short variable declaration (type inferred as int)
b := 20

// Zero-value initialization
var c int // c is initialized to 0

Type Identity and Strict Typing

In Go’s type system, int is a distinct, named type. It is not an alias for int32 or int64. Because Go enforces strict typing and lacks implicit type coercion, you cannot assign an int to a variable of type int32 or int64 without an explicit conversion, even if the underlying architecture guarantees identical bit widths.
var x int = 100
var y int64 = 100

// INVALID: Cannot use x (type int) as type int64 in assignment
// y = x 

// VALID: Requires explicit type conversion
y = int64(x)

Memory Alignment

The alignment guarantee for int matches its size. Evaluated via unsafe.Alignof(int(0)), it aligns to a 4-byte boundary on 32-bit architectures and an 8-byte boundary on 64-bit architectures. This behavior directly impacts struct padding when int fields are interleaved with smaller data types like bool or int8.
Tired of Poor Go Skills? Fix That With Deep Grasping!Learn More