---
source: https://iinventedlight.com/library/notes/go-encoding-base64.md
title: "encoding/base64: standard and URL-safe alphabets"
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, encoding/base64 package reference; Go, encoding/base64/base64.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-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-encoding-base64"
tags: [go, encoding, base64, rfc4648]
client: Librarian
sources:
  - id: S1
    title: "encoding/base64 package reference"
    publisher: Go
    url: https://pkg.go.dev/encoding/base64
    accessed: 2026-11-23
    license: "BSD-3-Clause"
  - id: S2
    title: "encoding/base64/base64.go source"
    publisher: Go
    url: https://go.dev/src/encoding/base64/base64.go
    accessed: 2026-11-23
    license: "BSD-3-Clause"
---
# encoding/base64: standard and URL-safe alphabets
**Answer:** Package base64 implements base64 encoding as specified by RFC 4648. StdEncoding is the standard base64 encoding. URLEncoding is the alternate base64 encoding that substitutes - and _ for + and /.

## The defined encodings

StdEncoding is the standard base64 encoding, as defined in RFC 4648.

URLEncoding is the alternate base64 encoding defined in RFC 4648.

RawStdEncoding matches StdEncoding except that it omits padding characters. RawURLEncoding is the same as URLEncoding but omits padding characters.

NewEncoder returns a stream encoder. NewDecoder constructs a stream decoder.

Decode reports a CorruptInputError when src contains invalid base64 data.

## What the source file defines

The package comment says the package implements base64 encoding as specified by RFC 4648.

An Encoding is a radix-64 scheme whose alphabet has 64 characters.

MIME (RFC 2045) and PEM (RFC 1421) use that common RFC 4648 encoding.

The RFC also defines an alternate encoding: - and _ are substituted for + and /.

StdPadding is the character '='. NoPadding is the value -1.

When writing into dst, the caller must ensure the buffer is large enough to hold all the decoded data.

## See also

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

## Claims

- id: C1
  claim: The package implements base64 encoding as specified by RFC 4648.
  source: S2
  evidence: "implements base64 encoding as specified by RFC 4648"

- id: C2
  claim: StdEncoding is the standard base64 encoding defined in RFC 4648.
  source: S1
  evidence: "StdEncoding is the standard base64 encoding"

- id: C3
  claim: URLEncoding is the alternate base64 encoding defined in RFC 4648.
  source: S1
  evidence: "URLEncoding is the alternate base64 encoding defined in RFC 4648"

- id: C4
  claim: RawStdEncoding is the same as StdEncoding but omits padding characters.
  source: S1
  evidence: "the same as StdEncoding but omits padding characters"

- id: C5
  claim: Invalid input can return a CorruptInputError.
  source: S1
  evidence: "CorruptInputError"

## Sources

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

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