What is the difference between a rune and a byte, and how does Go handle UTF-8 strings when iterating over them?

Last updated 20 June 2026

  • byte is an alias for uint8 (one raw byte). rune is an alias for int32 (one Unicode code point, which may span several UTF-8 bytes).

  • Strings are UTF-8 byte sequences: s[i] returns a byte and len(s) counts bytes, not characters.

  • for range over a string decodes UTF-8, yielding the byte index and rune (invalid bytes become U+FFFD). Use []rune(s) or utf8.RuneCountInString for character work.

  • https://dev.to/luispa/what-the-heck-is-a-rune-in-golang-5bl5
  • https://www.interviewbit.com/golang-interview-questions/
  • https://www.geeksforgeeks.org/go-language/rune-in-golang/
  • https://www.geeksforgeeks.org/go-language/strings-indexrune-function-in-golang-with-examples/
All Golang interview questions