---
source: https://iinventedlight.com/library/notes/go-lzw.md
title: "Go compress/lzw: Lempel-Ziv-Welch compressed data"
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, lzw package reference; The Go Authors, lzw reader.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-24
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-24
as_of: 2026-11-24
confidence: medium
untested: "Not reproduced (2026-11-24). 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-lzw"
tags: [go, lzw, compress, gif, tiff, pdf]
client: Librarian
sources:
  - id: S1
    title: "lzw package reference"
    publisher: The Go Authors
    url: https://pkg.go.dev/compress/lzw
    accessed: 2026-11-24
    license: "BSD-3-Clause"
  - id: S2
    title: "lzw reader.go source"
    publisher: The Go Authors
    url: https://go.dev/src/compress/lzw/reader.go
    accessed: 2026-11-24
    license: "BSD-3-Clause"
---
# Go compress/lzw: Lempel-Ziv-Welch compressed data
**Answer:** Package lzw implements the Lempel-Ziv-Welch compressed data format.

## Where this format appears

The package follows the Welch paper on high-performance data compression.

In particular it implements LZW as used in GIF and PDF file formats.

The TIFF file format uses a similar but incompatible version of the LZW algorithm.

A separate image tiff lzw package provides a TIFF implementation.

## Readers, writers, and bit order

It is the caller's responsibility to call Close when finished reading.

The litWidth for literal codes must be in the range 2 to 8 and is typically 8.

Order specifies the bit ordering in an LZW data stream.

LSB means Least Significant Bits first, as used in the GIF file format, while MSB is used in TIFF and PDF.

## See also

- [go-compress-flate](https://iinventedlight.com/library/notes/go-compress-flate/)
- [go-compress-gzip](https://iinventedlight.com/library/notes/go-compress-gzip/)
- [go-compress-zlib](https://iinventedlight.com/library/notes/go-compress-zlib/)

## Claims

- id: C1
  claim: Package lzw implements the Lempel-Ziv-Welch compressed data format.
  source: S1
  evidence: "Package lzw implements the Lempel-Ziv-Welch compressed data format"

- id: C2
  claim: TIFF uses a similar but incompatible version of the LZW algorithm.
  source: S1
  evidence: "similar but incompatible version of the LZW"

- id: C3
  claim: Order specifies the bit ordering in an LZW data stream.
  source: S2
  evidence: "Order specifies the bit ordering in an LZW data stream"

- id: C4
  claim: LSB means Least Significant Bits first, as used in GIF.
  source: S2
  evidence: "LSB means Least Significant Bits first, as used in the GIF"

## Sources

- [S1] lzw package reference. The Go Authors. https://pkg.go.dev/compress/lzw . License: BSD-3-Clause. Accessed 2026-11-24.

- [S2] lzw reader.go source. The Go Authors. https://go.dev/src/compress/lzw/reader.go . License: BSD-3-Clause. Accessed 2026-11-24.

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