On 64-bit platforms, the integer usually is 64 bits, so the maximum int value is “9223372036854775807”. To get the maximum value of the int64 type in Golang, you can use the “math.MaxInt64” constant.
The maximum value for an int type in the Golang is defined by the size of a type specified by the specification. Therefore, the maximum int value depends on the int size on the platform where the Golang code is executing.
Two predeclared integer types with implementation-specific sizes exist in Golang:
- Unsigned integers have either 32 or 64 bits.
- A signed integer has the same size as an unsigned integer.
Example 1
package main
import (
"fmt"
"math"
)
func main() {
fmt.Printf("int64 max: %d\n", math.MaxInt64)
}
Output
int64 max: 9223372036854775807
Example 2
package main
import (
"fmt"
"math"
)
func main() {
fmt.Printf("int32 max: %d\n", math.MaxInt32)
}
Output
int32 max: 2147483647
Example 3
If you want maximum int value based on the platform you are executing, go code, and try the below code.
package main
import (
"fmt"
)
func main() {
maxInt := int(^uint(0) >> 1)
fmt.Println(maxInt)
}
Output
9223372036854775807
You can see that I am using Macbook M1 64-bit OS. That’s why it returns the max int for 64-bit platforms.
That’s pretty much it.

Krunal Lathiya is a Software Engineer with over eight years of experience. He has developed a strong foundation in computer science principles and a passion for problem-solving. In addition, Krunal has excellent knowledge of Distributed and cloud computing and is an expert in Go Language.