# Base64

URL: https://softwaredictionary.org/terms/base64
Category: Programming Fundamentals
Last updated: 2026-10-05
Pronunciation: BAYS-siks-tee-FOR

In short: Base64 is a way to write any binary data, such as an image or a key, using only 64 safe text characters, so it can pass through systems built for text.

## What is Base64?

Base64 turns bytes into plain text. It takes the data three bytes at a time, splits those 24 bits into four groups of 6 bits, and writes each group as one of 64 characters: the letters A to Z and a to z, the digits 0 to 9, and `+` and `/`. When the data doesn't divide evenly into groups of three bytes, `=` signs pad the end.

It exists because many systems were built for text and can damage raw bytes: email, JSON, URLs, HTML and HTTP headers. With Base64, an image can travel inside an email or a JSON field, a small file can sit straight in a web page as a data URL, and HTTP Basic authentication carries the user name and password. A variant called base64url uses `-` and `_` instead of `+` and `/`, so the result is safe in addresses and file names; JWTs use it.

The price is size: every 3 bytes become 4 characters, so the encoded text is about a third larger than the data. And Base64 is an encoding, not encryption. Anyone can decode it in a moment, so it hides nothing: a password in Base64 is as exposed as one in plain text.

## Key takeaways

- Base64 writes any bytes using 64 text characters.
- Every 3 bytes become 4 characters, so the data grows by about a third.
- It carries binary data through email, JSON, URLs and HTTP headers.
- Base64 is an encoding, not encryption: anyone can decode it.

## Example: Encoding and decoding Base64 in JavaScript

```javascript
const encoded = btoa("hi!");   // "aGkh"
const decoded = atob(encoded); // "hi!"

// btoa only takes Latin-1 text, so other text goes through its UTF-8 bytes first
const bytes = new TextEncoder().encode("çay");
const safe = btoa(String.fromCharCode(...bytes)); // "w6dheQ=="
```

## Frequently asked questions

**Is Base64 encryption?**

No. Base64 only changes how the bytes are written, and anyone can turn it back without a key. To keep data secret, encrypt it; Base64 is just a way to carry the result as text.

**Why does Base64 sometimes end with = or ==?**

Base64 works on groups of three bytes. When the last group has only one or two, the output is padded with `==` or `=` so its length is a multiple of four. Some formats, such as JWTs, leave the padding out.

## Sources

- [RFC 4648: The Base16, Base32, and Base64 Data Encodings](https://www.rfc-editor.org/rfc/rfc4648.html)
- [MDN: Base64](https://developer.mozilla.org/en-US/docs/Glossary/Base64)

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
