All Articles
Base64 & Encoding·4 min read·October 2, 2026

Base64 in Golang: Encoding and Decoding Byte Slices with encoding/base64

Practical Go recipes for standard and URL-safe Base64 encoding using Go standard library encoding/base64 package.

TBy Toolstack Engineering
Recommended Free Tool

Try Toolstack's Base64 Encoder & Decoder

Free, instantaneous, and processes 100% locally in your browser.

Open Base64 Encoder & Decoder

Go provides built-in, highly optimized Base64 algorithms in the standard `encoding/base64` package.

Standard Encoding in Go

package main
import (
    "encoding/base64"
    "fmt"
)

func main() {
    data := []byte("Hello Golang!")
    encoded := base64.StdEncoding.EncodeToString(data)
    fmt.Println(encoded) // SGVsbG8gR29sYW5nIQ==

    decoded, err := base64.StdEncoding.DecodeString(encoded)
    if err != nil {
        panic(err)
    }
    fmt.Println(string(decoded))
}

URL-Safe Without Padding in Go

For JWT tokens and web queries, use `base64.RawURLEncoding`: ```go urlSafe := base64.RawURLEncoding.EncodeToString([]byte("token_payload")) ```

Tags:#Golang#Go#Backend#Data Processing

More Guides in Base64 & Encoding