---
source: https://iinventedlight.com/library/notes/go-unicode-utf8.md
title: "Go unicode/utf8: encode and decode UTF-8 runes"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go); BSD-3-Clause (Go); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Go, unicode/utf8 package reference; Go, unicode/utf8 source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-unicode-utf8"
tags: [go, unicode, utf8, runes, encoding]
client: Librarian
sources:
  - id: S1
    title: "unicode/utf8 package reference"
    publisher: Go
    url: https://pkg.go.dev/unicode/utf8
    accessed: 2026-11-23
    license: "BSD-3-Clause"
  - id: S2
    title: "unicode/utf8 source"
    publisher: Go
    url: https://go.dev/src/unicode/utf8/utf8.go
    accessed: 2026-11-23
    license: "BSD-3-Clause"
---
# Go unicode/utf8: encode and decode UTF-8 runes
**Answer:** Package utf8 implements functions and constants for text encoded in UTF 8. Helpers translate between runes and UTF 8 byte sequences. Valid reports whether a slice consists of valid UTF 8.

## Functions in the package reference

The package implements functions and constants to support text encoded in UTF 8.

Helpers include functions to translate between runes and UTF 8 byte sequences.

RuneCount returns the number of runes in p. RuneLen returns the number of bytes required to encode the rune.

Valid reports whether p consists entirely of valid UTF 8 encoded runes. DecodeRune unpacks the first UTF 8 encoding in p.

## The source comment

The source comment describes functions and constants to support text encoded in UTF 8.

Defining constants locally avoids this package depending on package unicode.

The conditions for RuneError and MaxRune are verified in the tests.

AppendRune appends the UTF 8 encoding of a rune to a slice.

## See also

- [go-encoding-json](https://iinventedlight.com/library/notes/go-encoding-json/)
- [go-encoding-hex](https://iinventedlight.com/library/notes/go-encoding-hex/)
- [go-bufio](https://iinventedlight.com/library/notes/go-bufio/)

## Claims

- id: C1
  claim: The package implements functions and constants for UTF-8 text.
  source: S1
  evidence: "functions and constants to support text encoded in UTF-8"

- id: C2
  claim: It includes functions to translate between runes and UTF-8 byte sequences.
  source: S1
  evidence: "translate between runes and UTF-8 byte sequences"

- id: C3
  claim: The source comment covers functions and constants for UTF-8 text.
  source: S2
  evidence: "Package utf8 implements functions and constants to support text encoded in"

- id: C4
  claim: The next line includes functions to translate between runes and UTF-8 bytes.
  source: S2
  evidence: "functions to translate between runes and UTF-8 byte sequences"

## Sources

- [S1] unicode/utf8 package reference. Go. https://pkg.go.dev/unicode/utf8 . License: BSD-3-Clause. Accessed 2026-11-23.

- [S2] unicode/utf8 source. Go. https://go.dev/src/unicode/utf8/utf8.go . License: BSD-3-Clause. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, unicode/utf8 package reference; Go, unicode/utf8 source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
