Go Data Types: A Comprehensive Guide for Developers
One of the fundamental aspects of any programming language is its type system. In Go (Golang), data types are designed to be simple and explicit, helping developers write reliable and efficient code. Understanding Go’s type system is essential for building well-optimized applications.
This guide covers every primary data type in Go with examples and explanations.
1. Boolean Type (bool)
The bool type represents truth values: true or false. It’s commonly used in control flow — if statements, loops, and conditions.
var isGoAwesome bool = true
Go does not allow implicit conversions between numeric and boolean types, ensuring stricter type safety than languages like C.
2. String Type (string)
A string in Go is an immutable sequence of bytes encoded in UTF-8. Strings are defined with double quotes.
var greeting string = "Hello, Go!"
Strings can be concatenated with +:
greeting := "Hello, " + "World!"
3. Integer Types
Go provides multiple signed and unsigned integer types with specific bit widths.
Signed Integers
| Type | Size | Range |
|---|---|---|
int | Platform-dependent (32 or 64-bit) | Varies |
int8 | 8-bit | -128 to 127 |
int16 | 16-bit | -32,768 to 32,767 |
int32 | 32-bit | -2,147,483,648 to 2,147,483,647 |
int64 | 64-bit | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
var age int = 25
var smallNumber int8 = 100
Unsigned Integers
| Type | Size | Range |
|---|---|---|
uint | Platform-dependent | 0 to max |
uint8 | 8-bit | 0 to 255 |
uint16 | 16-bit | 0 to 65,535 |
uint32 | 32-bit | 0 to 4,294,967,295 |
uint64 | 64-bit | 0 to 18,446,744,073,709,551,615 |
uintptr | Platform-dependent | Memory addresses |
var itemCount uint = 50
var memoryAddress uintptr
4. Byte and Rune Types
These are type aliases for numeric types, but are semantically meaningful when working with text.
byte (alias for uint8)
Represents a single raw byte of data or an ASCII character.
var letter byte = 'A'
rune (alias for int32)
Represents a Unicode code point, supporting characters from any language.
var unicodeChar rune = '✓'
5. Floating-Point Types
Go has two floating-point types for decimal numbers:
float32: 32-bit single precision.float64: 64-bit double precision (default for float literals).
var pi float64 = 3.14159
var e float32 = 2.71828
When in doubt, use float64 — it provides higher precision and is the default in Go.
6. Complex Number Types
Go includes built-in support for complex numbers:
complex64: Twofloat32values (real + imaginary).complex128: Twofloat64values.
var c complex64 = complex(1.5, 2.5)
fmt.Println(real(c)) // Output: 1.5
fmt.Println(imag(c)) // Output: 2.5
7. Type Conversions
Go is strongly typed — you cannot mix types without an explicit conversion. This prevents subtle bugs caused by implicit coercion.
Converting int to float64
var integer int = 10
var decimal float64 = float64(integer)
Converting between integer sizes
var small int8 = 127
var large int16 = int16(small)
Always be mindful of range limits when converting to smaller types — Go will not warn you if a value overflows.
8. Type Inference
The := short variable declaration lets Go infer the type automatically from the assigned value:
name := "Golang" // inferred as string
age := 30 // inferred as int
isDeveloper := true // inferred as bool
Type inference reduces boilerplate without sacrificing type safety — Go’s types remain strict at compile time.
Why Go’s Type System Matters
| Property | Benefit |
|---|---|
| Type Safety | Explicit conversions prevent implicit coercion bugs |
| Performance | Specific integer sizes (int8, int16, etc.) allow precise memory optimization |
| Clarity | byte and rune make intent clear when handling raw data vs. Unicode |
| Predictability | No surprising implicit casts at runtime |
Key Takeaways
- Go’s type system is explicit and strict — all type conversions must be intentional.
- Use
intfor general-purpose integers and only reach forint8/int16when memory optimization matters. - Use
runewhen working with Unicode characters; usebytefor raw binary data. - Use
float64as the default for floating-point arithmetic. - Leverage type inference with
:=to keep code concise without losing type safety.
Mastering Go’s type system will help you write code that is both correct and performant from day one.