Skip to main content
In Go, a byte is a built-in type alias for uint8. It is an unsigned 8-bit integer representing a value from 0 to 255. By convention, the Go compiler and standard library use byte to distinguish raw binary data and ASCII characters from standard numeric operations, even though byte and uint8 are strictly identical at compile time.

Type Characteristics

  • Underlying Type: uint8
  • Memory Footprint: 1 byte (8 bits)
  • Value Range: 0 to 255 (0x00 to 0xFF)
  • Default Zero Value: 0

Syntax and Initialization

A byte can be initialized using standard integer literals, character literals (enclosed in single quotes), hexadecimal literals, or binary literals.
Note: Character literals in Go are untyped constants representing Unicode code points (defaulting to rune / int32). When assigned to a byte, the compiler verifies that the constant’s integer value fits within the 8-bit bounds (0-255). Assigning a character whose Unicode code point exceeds 255 (e.g., 'Ā' which is U+0100 / 256, or '😊') to a byte will result in a compile-time overflow error.

Type Equivalence

Because byte is an alias and not a distinct, newly defined type, it is completely interchangeable with uint8. No explicit type conversion is required when assigning or comparing byte and uint8 variables.

Interaction with Strings

In Go, a string is fundamentally a read-only slice of bytes ([]byte). The language provides built-in syntax for converting between strings and byte slices, which allocates new memory and copies the underlying array to maintain string immutability.

Formatting Verbs

When using the fmt package, a byte can be formatted in several ways depending on the desired representation of the 8-bit value:
Tired of Poor Go Skills? Fix That With Deep Grasping!Learn More