---
source: https://iinventedlight.com/library/notes/go-unicode-utf16.md
title: "Go unicode/utf16: encode and decode UTF-16 sequences"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (The Go Authors); BSD-3-Clause (The Go Authors); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Go Authors, utf16 package - unicode/utf16; The Go Authors, utf16.go (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-27
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-27
as_of: 2026-11-27
confidence: medium
untested: "Not reproduced (2026-11-27). 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-utf16"
tags: [go, utf16, unicode, surrogate, rune]
client: Librarian
sources:
  - id: S1
    title: "utf16 package - unicode/utf16"
    publisher: The Go Authors
    url: https://pkg.go.dev/unicode/utf16
    accessed: 2026-11-27
    license: "BSD-3-Clause"
  - id: S2
    title: "utf16.go (source)"
    publisher: The Go Authors
    url: https://go.dev/src/unicode/utf16/utf16.go
    accessed: 2026-11-27
    license: "BSD-3-Clause"
---
# Go unicode/utf16: encode and decode UTF-16 sequences
**Answer:** Package utf16 implements encoding and decoding of UTF-16 sequences, including surrogate pairs.

## Encode and decode whole slices

Encode returns the UTF-16 encoding of a slice of Unicode code points.

Decode returns the Unicode code point sequence represented by a UTF-16 slice.

AppendRune appends the UTF-16 encoding of a rune to a uint16 buffer and returns the extended buffer.

If that rune is not a valid Unicode code point, AppendRune appends the encoding of U+FFFD.

## Surrogate pairs and rune length

A surrogate pair encodes a single supplementary code point as two 16-bit words.

IsSurrogate reports whether a Unicode code point can appear in a surrogate pair.

EncodeRune returns the surrogate pair for a rune.

If the rune is not a valid code point or does not need a pair, EncodeRune returns U+FFFD, U+FFFD.

DecodeRune decodes a surrogate pair.

DecodeRune returns the Unicode replacement code point U+FFFD when the pair is not a valid UTF-16 surrogate pair.

RuneLen returns the number of 16-bit words in the UTF-16 encoding of a rune, or -1 if the rune is not valid to encode in UTF-16.

## See also

- [go-unicode](https://iinventedlight.com/library/notes/go-unicode/)
- [go-unicode-utf8](https://iinventedlight.com/library/notes/go-unicode-utf8/)
- [rust-strings-utf8](https://iinventedlight.com/library/notes/rust-strings-utf8/)

## Claims

- id: C1
  claim: The package encodes and decodes UTF-16 sequences.
  source: S1
  evidence: "Package utf16 implements encoding and decoding of UTF-16 sequences"

- id: C2
  claim: DecodeRune decodes a UTF-16 surrogate pair.
  source: S1
  evidence: "DecodeRune returns the UTF-16 decoding of a surrogate pair"

- id: C3
  claim: IsSurrogate reports whether a code point can appear in a surrogate pair.
  source: S2
  evidence: "IsSurrogate reports whether the specified Unicode code point"

## Sources

- [S1] utf16 package - unicode/utf16. The Go Authors. https://pkg.go.dev/unicode/utf16 . License: BSD-3-Clause. Accessed 2026-11-27.

- [S2] utf16.go (source). The Go Authors. https://go.dev/src/unicode/utf16/utf16.go . License: BSD-3-Clause. Accessed 2026-11-27.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, utf16 package - unicode/utf16; The Go Authors, utf16.go (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).
