A byte is Go’s meaningful name for uint8: an unsigned, fixed-width eight-bit integer ranging from 0 to 255. The alias signals that a value represents data rather than an ordinary numeric quantity. section 3.1
The distinction matters most when handling raw contents. Standard-library APIs commonly accept or return byte sequences as []byte, allowing code to process text or binary files without assuming a text encoding. section 3.1 section 2.6.4
Use byte-oriented values when:
- Representing individual eight-bit data units or a slice of raw file contents. section 3.1 section 2.6.4
- Passing data to APIs that operate on []byte rather than strings. section 3.1 section 2.6.4
- Converting raw bytes to string only after deciding that the loaded file should be treated as text. section 2.6.4
Count words from raw file data
contents, err := os.ReadFile("notes.txt") if err != nil { return err } words := strings.Fields(string(contents)) os.ReadFile returns []byte because a file may contain binary data. For text, convert those bytes to string; for byte-oriented processing, use bytes.Fields(contents) instead. section 2.6.4
Table 3.1 Predeclared integer types
| Type name |
Description |
Value vange |
|---|---|---|
|
|
Signed integers |
32 or 64 bits, depending on your architecture |
|
|
Signed 8-bit integers |
-128 to 127 |
|
|
Signed 16-bit integers |
-32,768 to 32,767 |
|
|
Signed 32-bit integers |
-2,147,483,648 to 2,147,483,647 |
|
|
Signed 64-bit integers |
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
|
|
Unsigned integers |
32 or 64 bits, depending on your architecture |
|
|
Unsigned 8-bit integers |
0 to 255 |
|
|
Unsigned 16-bit integers |
0 to 65,535 |
|
|
Unsigned 32-bit integers |
0 to 4,294,967,295 |
|
|
Unsigned 64-bit integers |
0 to 18,446,744,073,709,551,615 |
|
|
An alias for |
|
|
|
An alias for |
Compare byte with uint8 and the other predeclared integer types to distinguish its representation from architecture-dependent integers. section 3.1

