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.
Try Toolstack's Base64 Encoder & Decoder
Free, instantaneous, and processes 100% locally in your browser.
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")) ```
More Guides in Base64 & Encoding
Explore More Free Tools on Toolstack
Client-side developer utilities, image converters, calculators, and educational engineering guides.
Word Counter
Count words, characters with/without spaces, sentences, and paragraphs in real time with reading speed metrics.
PDF Compressor
Reduce PDF document file size directly in your browser with zero server uploads.
Image Compressor & Resizer
Batch compress and scale JPG, PNG, and WebP images with custom quality settings.
URL Encoder & Decoder
Encode and decode query strings, special characters, and parameters with RFC 3986 percent-encoding.
JSON Validator & Formatter
Beautify, validate, minify, and auto-fix JSON syntax errors with real-time line/column diagnostics.
HEIC to JPG Converter
Convert Apple iPhone HEIC and HEIF photos to high-quality JPG directly in your browser.