👈 Decode Base64 to a string in Go

base64 encoding strings

To decode a Base64 encoded string, use the DecodeString() function from the encoding/base64 standard library package. This function takes an encoded string as an argument and returns a byte slice, along with the decoding error. To get the decoded string, convert the byte slice to a string.

Check also how to encode a string to Base64 in Go.

package main

import (

func main() {
    rawDecodedText, err := base64.StdEncoding.DecodeString("aGVsbG8gZnJvbSBnb3NhbXBsZXMuZGV2IGJhc2U2NCBlbmNvZGluZyBleGFtcGxlIQ==")
    if err != nil {
    fmt.Printf("Decoded text: %s\n", rawDecodedText)


Decoded text: hello from gosamples.dev base64 encoding example!

The StdEncoding is an object representing the standard base64 encoding, as defined in RFC 4648, and the DecodeString() is its method.

👉 Encode a string to Base64 in Go

Learn how to encode strings to Base64 using encoding/base64 package
base64 encoding strings

🧮 Sort a string slice containing numbers in Go

Learn how to sort strings with numbers in natural order
sort slice strings

🍒 Concatenate strings in Go

Learn the differences between string concatenation methods
introduction strings