Mahdi.Kh
September 21, 2026
In this part, we get familiar with numeric data types and learn how to use them.
Go's numbers are divided into the following three categories:
Integers (int)
Floating-point numbers (float)
Complex numbers (complex)
An integer is a number with no fractional part. Integers themselves are divided into two categories: signed and unsigned. The unsigned form can't store negative numbers.
Depending on how much memory is needed, Go offers 8, 16, 32, and 64-bit forms of integers. For example, with 8 bits we can store 28 = 256 numbers, meaning the signed form can store from -128 to 127, and the unsigned form can store from 0 to 255.
There are two other integer types, named int and uint, whose size depends on the architecture of the system the program runs on.
On 32-bit systems, the size of int and uint is 32 bits, and on 64-bit systems, their size is 64 bits.
The int type is used by default for integers in Go.
Here, we used the unsafe package to measure how much memory each variable uses.
If you run the program above on a 64-bit system, a's size will be 8 bytes (64 bits), while b's size is always 4 bytes (32 bits).
If you run the program above on a 32-bit system, a's size will be 4 bytes (32 bits), while b's size is still 4 bytes (32 bits).
This difference shows why, in some cases, you might want to be sure of the exact size, especially in applications that need consistent, predictable data sizes.
Floating-point numbers in Go come in 32-bit and 64-bit forms. In the 32-bit form, up to 7 decimal digits can be stored, and in the 64-bit form, up to 16 decimal digits can be stored.
If we don't specify the memory size, a floating-point number is stored in memory as 64-bit by default.
Note: floating-point numbers are stored approximately, and because of this approximation, they aren't suitable for important calculations that need high precision, and they can lead to unpredictable results.
In the example above, we expect the result of adding a and b to equal c, but that doesn't happen.
Go also supports complex numbers. Complex numbers come in 64-bit and 128-bit forms.
complex64: complex numbers whose real and imaginary parts are of type float32
complex128: complex numbers whose real and imaginary parts are of type float64
To define complex numbers, you can use the complex function, or separate the imaginary part from the real part with a + sign and the i suffix.
If we don't specify the memory size (as in the example above), complex128 is used by default.
To access the real and imaginary parts, we use the real and imag functions, respectively:
To get familiar with arithmetic operators, take a look at the example below:
In this part, we got familiar with Go's numeric data types and looked at arithmetic operators.
Previous part: Constants | Golang basics
Next part: Boolean | Golang basics