YAML to Base64 Converter
Paste YAML and get Base64 you can drop into a Kubernetes Secret, a CI variable or an environment variable. It checks the YAML as you type and can match the output of the base64 command. Switch direction to decode Base64 back to YAML.
every 3 bytes of YAML = 4 Base64 characters
bG9nX2xldmVsOiBpbmZvCnBvcnQ6IDgwODAKZmVhdHVyZXM6CiAgLSBzZWFyY2gKICAtIGV4cG9ydA==
Valid YAML · 3 top-level keys · 58 bytes → 80 characters
Everything runs in your browser; nothing is uploaded.
How to Convert YAML to Base64
Base64 does not read or change your YAML. It takes the file’s bytes, exactly as saved, and writes them using only letters, digits, +, / and =. The result fits on one line with no spaces, colons or quotes, so it can sit safely inside another file or a variable. Comments, indentation and key order all come back untouched when you decode it.
- Paste the YAML into the box above, or open the file in a text editor and copy all of it.
- Leave the output on One line, which is what Kubernetes, GitHub Actions and most tools expect.
- If you want the same result as running
base64on the file, turn on + final newline. Saved files almost always end with one. - Copy the Base64. To check it, switch to Base64 → YAML and the original comes back.
To do it from a terminal instead:
| System | Encode | Decode |
|---|---|---|
| Linux | base64 -w 0 config.yaml | base64 -d config.b64 > config.yaml |
| macOS | base64 -i config.yaml | base64 -D -i config.b64 -o config.yaml |
| Windows | [Convert]::ToBase64String([IO.File]::ReadAllBytes("$PWD\config.yaml")) | [IO.File]::WriteAllBytes("$PWD\config.yaml", [Convert]::FromBase64String($b64)) |
On Linux, -w 0 matters: without it the output is broken into lines of 76 characters, and most places you paste it into expect a single line. macOS does not wrap unless you ask. The Windows commands run in PowerShell and read the file’s bytes directly, so nothing is added or changed.
Worked Example: env: prod to Base64
The one-line YAML env: prod is 9 characters, and each is one byte, space included.
Step 1: Turn the text into bytes
Step 2: Split the bytes into groups of three
Step 3: Each group of 3 bytes becomes 4 Base64 characters
Result: ZW52OiBwcm9k. 9 bytes divide evenly into threes, so there is no = padding on the end.
Save the same line in a file and encode the file, and you get ZW52OiBwcm9kCg==. The extra Cg== is the newline at the end of the file. It is the single most common reason two encodings of “the same” YAML differ. Try it with the third example in the tool and the + final newline switch.
YAML in a Kubernetes Secret or CI Variable
The usual reason to Base64-encode YAML is to store a whole config file as a single value. In a Kubernetes Secret, every value under data must be Base64. Here a two-line config.yaml (with its final newline) becomes one value:
apiVersion: v1
kind: Secret
metadata:
name: app-config
type: Opaque
data:
config.yaml: bG9nX2xldmVsOiBpbmZvCnBvcnQ6IDgwODAKYou often do not need to encode by hand. These do it for you:
kubectl create secret generic app-config --from-file=config.yamlreads the file and encodes it, final newline included.- Put the plain YAML under
stringDatainstead ofdata, using a|block, and Kubernetes encodes it when you apply the manifest.
To read a value back out, decode it:
kubectl get secret app-config -o jsonpath='{.data.config\.yaml}' | base64 -dCI systems work the same way. A kubeconfig or a multi-line config is easier to store as a GitHub Actions or GitLab CI secret once it is one line of Base64, and GitHub’s documentation recommends Base64 for storing blobs as secrets. Encode it with base64 -w 0 kubeconfig.yaml, save the output as a secret, then decode it in the job:
- run: echo "$KUBECONFIG_B64" | base64 -d > kubeconfig.yaml
env:
KUBECONFIG_B64: ${{ secrets.KUBECONFIG_B64 }}GitHub limits each secret to 48 KB, and Base64 is about a third bigger than the file, so a YAML file of up to roughly 36 KB fits.
Why Doesn’t My Base64 Match?
If two tools give different Base64 for the same YAML, they were given different bytes. The text looks the same on screen, but something invisible differs. These are the usual causes:
| Cause | What you see | Fix |
|---|---|---|
| echo adds a newline | echo "hello" | base64 gives aGVsbG8K, not aGVsbG8= | echo -n "hello" or printf '%s' "hello" |
| The file ends with a newline | An extra Cg==, K or o= near the end | Turn on + final newline to match the file |
| Line wrapping | Line breaks every 76 characters | base64 -w 0, or choose One line |
| Windows line endings | A longer result; decoded text shows CRLF | Save the file with LF line endings |
| Byte-order mark | Base64 starts with 77u/ | Save as “UTF-8” without BOM |
| URL-safe Base64 | - and _ instead of + and /, no = | Both decode the same; pick the one your tool wants |
The byte-order mark usually comes from Windows PowerShell 5 (-Encoding utf8 on Set-Content or Out-File) or from older editors. Kubernetes and most YAML tools cope with it, but it changes the Base64. Plain Out-File and > are worse: they save UTF-16, which doubles the size and starts the Base64 with //. Decoding a value in this tool shows whether it had a byte-order mark or Windows line endings, and flags UTF-16.
Frequently asked questions
Is Base64 encryption?
No. Anyone can decode Base64 instantly, so it hides nothing. Kubernetes Secrets are only Base64-encoded and are stored unencrypted by default unless the cluster turns on encryption at rest. Limit who can read them, or use a secrets manager, for real passwords and keys.
Does Base64 change my YAML?
No. It encodes the exact characters, so comments, indentation, quotes and key order all come back identical when you decode. It does not check or reformat the YAML; this tool checks it separately and still encodes it if it has mistakes.
How much bigger is the Base64?
About a third. Every 3 bytes become 4 characters, with = added to round up the last group, so a 3 KB YAML file becomes 4 KB of Base64.
Should I use data or stringData in a Kubernetes Secret?
Use stringData if you want to write the YAML as plain text and let Kubernetes encode it. Use data if you already have the Base64, such as from this tool or from base64 -w 0. If a key appears in both, stringData wins.
Sources
- RFC 4648: The Base16, Base32, and Base64 Data Encodings: the Base64 and URL-safe alphabets
- Kubernetes: Secrets: data and stringData, encryption at rest
- Kubernetes: Managing Secrets using kubectl: creating and decoding Secrets
- GitHub Docs: Using secrets in GitHub Actions: the 48 KB limit and storing Base64 blobs
- GNU coreutils: base64: the -w and -d options and the 76-character default
Related Tools
Build and preview Valorant crosshair settings.
Search common Vim commands.
Turn JSON rows into bar, line, or pie charts.
Convert WebP files and Base64 data in both directions.
Convert GIF files and Base64 data in both directions.
Save any GIF frame, or all frames, as JPG.