Golang integer types: int, int32, int64, uint, and sizes

Golang int and go int types, golang int types and sizes, golang int vs int32, uint and sized integers, byte and rune aliases, and how golang data types size depends on int versus int8–int64.

Published

Updated

Read time 4 min read

Reviewed byDeepak Prasad

Golang integer types: int, int32, int64, uint, and sizes

When people search for golang int, go int, int golang, golang int types, golang int size, golang int vs int32, golang data types, golang types, golang data types size, or go int types, they are usually mapping familiar “integer” ideas onto Go’s numeric rules. Go splits integers into implementation-sized types (int and uint) and fixed-width types (int8 through int64 and uint8 through uint64), plus the aliases byte (uint8) and rune (int32). The language spec is the source of truth for names and widths.

Tested with Go 1.24 on Linux.


Signed integer types

The signed golang types are int, int8, int16, int32, and int64. The first is special: int is implementation-specific—typically the same width as a machine word (often 32 bits on 386 and 64 bits on amd64). The others are always exactly as wide as their names suggest.

Type Size Signed Typical use
int 32 or 64 bits per implementation yes Indexes, len, cap, general arithmetic on the current platform
int8 8 bits yes Small packed fields, tight structs
int16 16 bits yes Legacy formats, sensors, narrow ranges
int32 32 bits yes Stable wire size, rune, APIs that require 32-bit ints
int64 64 bits yes Epoch-nanosecond times, large counters, explicit 64-bit APIs

Exact min and max values are the usual two's-complement ranges for each width; the math package exposes constants such as math.MaxInt32 and math.MaxInt64 when you need them in code.

golang int vs int32

The phrase golang int vs int32 is mostly about portability: int32 is always four bytes. int matches the natural word-sized integer for the target, so the same source line can mean a 32-bit or 64-bit variable depending on GOARCH. Use int32 when a protocol or database column is explicitly 32-bit; use int when you follow for i := 0; i < len(s); i++ style loops and standard library APIs that take int.

Seeing golang int size on your machine

You can print storage sizes with unsafe.Sizeof. Sizes are compile-time constants for a given build configuration:

go
package main

import (
	"fmt"
	"unsafe"
)

func main() {
	var i int
	var i32 int32
	var i64 int64
	fmt.Printf("int %d bytes, int32 %d bytes, int64 %d bytes\n",
		unsafe.Sizeof(i), unsafe.Sizeof(i32), unsafe.Sizeof(i64))
}
Output

On a typical 64-bit Linux build, int and int64 are often eight bytes and int32 is four; on a 32-bit int build, int is usually four bytes while int64 stays eight.


Unsigned integer types

Unsigned golang types are uint, uint8, uint16, uint32, and uint64. uint is implementation-sized the same way int is; the uint8uint64 types have fixed bit widths. Unsigned arithmetic wraps modulo 2 to the power of the type's bit width; there is no negative representable value.

Type Size Notes
uint 32 or 64 bits Matches unsigned word size for the implementation
uint8 8 bits Alias name byte
uint16 16 bits Larger unsigned ranges without uint32 overhead
uint32 32 bits CRCs, IPv4 addresses as numbers, masks
uint64 64 bits Large bitmasks, hardware registers, sync/atomic on 64-bit values

Aliases: byte and rune

  • byte is an alias for uint8. Use it for raw binary data and UTF-8 bytes.
  • rune is an alias for int32. Use it for Unicode code points (a single rune is one code point, not necessarily one user-visible character in all languages).

Choosing among golang types

  1. Default loops and slices: prefer int for indexes and lengths so you match len and standard library signatures.
  2. Stable layout: pick int32, int64, or an unsigned fixed width when a file format, RPC schema, or SQL type dictates the width.
  3. Interop and narrowing: converting between int and int64 is explicit in Go; if you narrow int64 to int, read int and int64 conversions for platform caveats.
  4. Clarity over micro-optimization: smaller ints save memory only when they matter at scale; otherwise fixed widths mainly document intent.

Summary

Go’s integer story separates implementation-sized int/uint from fixed-width int8int64 and uint8uint64, which answers most golang int size and golang data types size questions in terms of the spec and GOARCH. golang int vs int32 comes down to fixed four-byte int32 versus variable-width int. For everyday code, int stays the default for golang int / go int style arithmetic; reach for sized types and byte/rune aliases when the problem domain names a width or encoding.


References


Frequently Asked Questions

1. What is golang int size and how is it different from int32?

The predeclared type int is either 32 or 64 bits depending on the implementation (for example amd64 versus 386); int32 is always 32 bits. That is the core of golang int vs int32: int matches the natural word size for the platform, while int32 is fixed for APIs, serialization, and bitwise layouts.

2. What golang int types exist besides int?

Go provides signed int8, int16, int32, and int64 with fixed widths, plus unsigned uint, uint8, uint16, uint32, and uint64. The byte alias is uint8 and the rune alias is int32 for UTF-32 code units.

3. How do golang data types size for integers affect my code?

Use int for indexes, lengths, and general loops; use fixed-width types at boundaries (files, wire formats, databases) so behavior does not change when moving between 32-bit and 64-bit builds. Converting int64 to int can truncate on 32-bit int; see the int conversion article if you narrow types.

4. Are go int types the same as Java or C int?

Not exactly: in Go, int is implementation-sized, not guaranteed 32 bits. If you need a 32-bit signed integer in Go, use int32 explicitly.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …