encoding/base64

Encoding
import "encoding/base64"

Implements base64 encoding as specified by RFC 4648.

Example

package main

import (
    "encoding/base64"
    "fmt"
)

func main() {
    encoded := base64.StdEncoding.EncodeToString([]byte("Hello"))
    fmt.Println(encoded)  // SGVsbG8=
    decoded, _ := base64.StdEncoding.DecodeString(encoded)
    fmt.Println(string(decoded))  // Hello
}

Key Types & Functions

StdEncodingURLEncodingEncodeToStringDecodeString

About encoding/base64

The encoding/base64 package (imported as encoding/base64) belongs to the Encoding category of Go packages. Implements base64 encoding as specified by RFC 4648.

Go's standard library is one of the language's greatest strengths, providing production-ready implementations for networking, cryptography, encoding, I/O, and more. The encoding/base64 package follows Go's philosophy of simplicity and composability — small, focused packages that combine through interfaces like io.Reader and io.Writer.

When using encoding/base64 in production, follow Go best practices: handle errors explicitly, use context for cancellation and timeouts, prefer composition over inheritance, and write table-driven tests. The Go documentation at pkg.go.dev provides comprehensive API references and examples for every exported type and function.

Related Packages