Converting int to int64 in Go (often searched as golang int to int64, golang convert int to int64, go int to int64, or golang cast int to int64) is a widening conversion: write int64(i). The reverse—golang int64 to int, int64 to int golang, or golang convert int64 to int—is int(i64), but that only preserves the value when int is wide enough. This page covers both directions, an optional strconv path, and portability when int is 32 bits.
Tested with Go 1.24 on Linux.
int to int64 in Go
An int is either 32 or 64 bits depending on the implementation (GOARCH). An int64 is always 64 bits. Converting from int to int64 widens the value, so every representable int fits in int64 with the same numeric value.
package main
import "fmt"
func main() {
i := 1104
var i64 int64 = int64(i)
fmt.Printf("i value: %v, i type: %T\n", i, i)
fmt.Printf("i64 value: %v, i64 type: %T\n", i64, i64)
}Running the program prints the int line, then the int64 line with the same numeric value and different types.
int64 to int in Go
For golang int64 to int, use int(i64). That is a narrowing conversion: the value is converted to fit int per the language rules for non-constant conversions between integer types. On typical linux/amd64 builds, int is 64 bits, so ordinary int64 values like 1104 or math.MaxInt64 map to the same integer. On platforms where int is 32 bits, values outside the int32 range are not preserved.
The following program uses math.MaxInt64 and math.MinInt64 with corrected format verbs for the max line:
package main
import (
"fmt"
"math"
)
func main() {
maxI64 := math.MaxInt64
maxI := int(maxI64)
minI64 := math.MinInt64
minI := int(minI64)
fmt.Printf("min i value: %v, min i type: %T\n", minI, minI)
fmt.Printf("min i64 value: %v, min i64 type: %T\n", minI64, minI64)
fmt.Printf("max i value: %v, max i type: %T\n", maxI, maxI)
fmt.Printf("max i64 value: %v, max i64 type: %T\n", maxI64, maxI64)
}On linux/amd64 the output ends with both max values as 9223372036854775807 and types int and int64. If you build the same source with GOARCH=386 (32-bit int), the int64 lines are unchanged but the int lines show truncated values, for example:
min i value: 0, min i type: int
min i64 value: -9223372036854775808, min i64 type: int64
max i value: -1, max i type: int
max i64 value: 9223372036854775807, max i64 type: int64If you need int only when the value fits, check explicitly, for example against math.MaxInt / math.MinInt (Go 1.17+) or compare against int64(math.MaxInt32) when you know you target 32-bit int.
Optional: int to string to int64 with strconv
You do not need strings for a normal int to int64 golang conversion. If the data is already textual, use strconv.ParseInt with bit size 64, or strconv.Atoi and then int64(i) when the value fits in int.
package main
import (
"fmt"
"strconv"
)
func main() {
i := 1104
fmt.Printf("i value: %v, i type: %T\n", i, i)
iStr := strconv.Itoa(i)
i64, err := strconv.ParseInt(iStr, 10, 64)
if err != nil {
fmt.Println("parse error:", err)
return
}
fmt.Printf("i64 value: %v, i64 type: %T\n", i64, i64)
}Summary
Golang convert int to int64 and golang cast int to int64 both mean writing int64(i) for an int value i. The reverse—golang convert int64 to int or int64 to int—is int(i64), which is only safe to treat as “same number” when int is wide enough or the int64 is provably in range. Prefer direct conversions over string detours unless you are parsing or formatting text; fix any old examples that print the wrong verb for maxI so readers can trust boundary output on 64-bit int.
References
- The Go Programming Language Specification: Conversions
- Effective Go: Type conversions
strconvpackage documentation

