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
- 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.
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
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.},
}
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.
- go-encoding-base64.schema.json (schema; CC-BY-4.0)
- go-encoding-base64.table.json (table; CC-BY-4.0)
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.