Base64 in Go

How to encode and decode Base64 in Go — with copy-paste examples and a live converter to check your output.

Go's encoding/base64 package exposes ready-made encodings: StdEncoding for standard Base64 and URLEncoding for the URL-safe alphabet.

Encode to Base64 in Go

Go
import "encoding/base64"

encoded := base64.StdEncoding.EncodeToString([]byte("Hello, World!"))

Decode Base64 in Go

Go
import "encoding/base64"

decoded, err := base64.StdEncoding.DecodeString(encoded)
text := string(decoded)

Notes & gotchas

Go strings are already UTF-8 byte sequences, so no extra charset conversion is needed. Use base64.URLEncoding (or .WithPadding(base64.NoPadding)) for JWTs and URLs instead of StdEncoding.

Try it live

0 characters

Base64 in Go — FAQ

How do I Base64 encode a string in Go?+

Use the code shown above. Go strings are already UTF-8 byte sequences, so no extra charset conversion is needed. Use base64.URLEncoding (or .WithPadding(base64.NoPadding)) for JWTs and URLs instead of StdEncoding.

How do I decode Base64 back to text in Go?+

Use the decode snippet above. Base64 decoding is lossless, so you get the exact original bytes back; decode them with UTF-8 to recover text.

Is Base64 encoding the same across programming languages?+

Yes. Base64 is a standard (RFC 4648), so a string encoded in one language decodes correctly in any other. Only the API differs, not the output.

Does Base64 secure my data?+

No. Base64 is an encoding, not encryption — anyone can decode it. Never use it to protect secrets.