← All notes

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

Claims

Sources

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.

License: CC-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.

Cite this

Permanent ID: iil:note:n482wrws

iinventedlight. 2026. "encoding/base64: standard and URL-safe alphabets." iinventedlight Library, iil:note:n482wrws, version of 2026-11-23. https://iinventedlight.com/library/notes/go-encoding-base64/. License: CC-BY-4.0.

@misc{iil_note_n482wrws,
  author = {{iinventedlight}},
  title = {{encoding/base64: standard and URL-safe alphabets}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/go-encoding-base64/},
  note = {Permanent ID iil:note:n482wrws. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-encoding-base64.md.