---
source: https://iinventedlight.com/library/notes/go-pem.md
title: "Go encoding/pem: the PEM data encoding"
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, encoding/pem; The Go Authors, encoding/pem 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-pem"
tags: [go, pem, encoding, tls, certificates]
client: Librarian
sources:
  - id: S1
    title: "encoding/pem"
    publisher: The Go Authors
    url: https://pkg.go.dev/encoding/pem
    accessed: 2026-11-24
    license: "BSD-3-Clause"
  - id: S2
    title: "encoding/pem source"
    publisher: The Go Authors
    url: https://go.dev/src/encoding/pem/pem.go
    accessed: 2026-11-24
    license: "BSD-3-Clause"
---
# Go encoding/pem: the PEM data encoding
**Answer:** The most common use of PEM encoding today is in TLS keys and certificates.

## What the package does

Package pem implements the PEM data encoding, which originated in Privacy Enhanced Mail.

A Block represents a PEM encoded structure.

That encoding is still widely used for keys and certificates in TLS.

If a block has invalid headers and cannot be encoded, EncodeToMemory returns nil.

## What the source comments add

Decode will find the next PEM formatted block in the input.

It returns that block and the remainder of the input.

The decoded bytes of the contents are typically a DER encoded ASN.1 structure.

Encode writes the PEM encoding of a block to the writer.

## See also

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

## Claims

- id: C1
  claim: The most common use of PEM encoding today is in TLS keys and certificates.
  source: S1
  evidence: "The most common use of PEM encoding today is in TLS keys and certificates."

- id: C2
  claim: A Block represents a PEM encoded structure.
  source: S1
  evidence: "A Block represents a PEM encoded structure."

- id: C3
  claim: If a block has invalid headers and cannot be encoded, EncodeToMemory returns nil.
  source: S1
  evidence: "If b has invalid headers and cannot be encoded, EncodeToMemory returns nil."

- id: C4
  claim: It returns that block and the remainder of the input.
  source: S2
  evidence: "It returns that block and the remainder of the input."

## Sources

- [S1] encoding/pem. The Go Authors. https://pkg.go.dev/encoding/pem . License: BSD-3-Clause. Accessed 2026-11-24.

- [S2] encoding/pem source. The Go Authors. https://go.dev/src/encoding/pem/pem.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, encoding/pem; The Go Authors, encoding/pem 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).
