HTTP Basic authentication credentials
Input
user:pa55word
Result
dXNlcjpwYTU1d29yZA==
This is exactly what an Authorization: Basic header carries. It is encoded for transport only, which is why Basic auth requires HTTPS.
Convert text to Base64 for transport, embeds, and quick debugging.
RW5jb2RlIHRoaXMgZGV2ZWxvcGVyIG5vdGUu
Understand the format
Base64 re-expresses arbitrary bytes using 64 printable characters, so binary or awkward text survives channels that only accept plain ASCII.
Base64 takes the input three bytes at a time, which is 24 bits, and splits those bits into four groups of six. Each 6-bit group indexes into a 64-character alphabet of A-Z, a-z, 0-9, plus and slash. When the input length is not a multiple of three, the final group is padded with one or two equals signs so the output length stays a multiple of four.
The consequence is a predictable 33% size increase: every three bytes in produce four characters out. That overhead is the price of passing binary data through email headers, JSON string values, HTML attributes, and other places where raw bytes would be mangled.
Base64 encodes bytes, not characters, so any text must first be turned into bytes by a character encoding. This page uses UTF-8, which is what virtually every modern API expects. It matters for anything outside ASCII: the five-character string "héllo" is six bytes in UTF-8 because é occupies two bytes, and its Base64 form is aMOpbGxv rather than what a one-byte-per-character encoding would produce.
It is worth stating plainly, because it is the single most common misunderstanding: Base64 is an encoding, not encryption. Anyone can decode it instantly without a key. Encoding a password or an API key does not protect it in any way.
Step by step
Encoding uses the browser TextEncoder and btoa in the page. Values you paste, including credential-shaped strings, are never sent to a server.
Worked examples
Input
user:pa55word
Result
dXNlcjpwYTU1d29yZA==
This is exactly what an Authorization: Basic header carries. It is encoded for transport only, which is why Basic auth requires HTTPS.
Input
héllo
Result
aMOpbGxv
Five characters, six UTF-8 bytes, eight Base64 characters. The first four output characters, aMOp, encode the bytes 68 c3 a9, where c3 a9 is the two-byte UTF-8 form of é.
Reference
| Input bytes | Bits | Base64 output | Padding |
|---|---|---|---|
| M a n (3 bytes) | 24 bits split into four 6-bit groups | TWFu | None needed |
| M a (2 bytes) | 16 bits padded to 18 | TWE= | One = character |
| M (1 byte) | 8 bits padded to 12 | TQ== | Two = characters |
| Alphabet | A-Z a-z 0-9 + / | 64 symbols, 6 bits each | URL-safe variant swaps + / for - _ |
Practical Guide
Troubleshooting
FAQ
No, and it is not intended to be. It is a transport encoding defined in RFC 4648. Anyone can reverse it, so it provides no confidentiality whatsoever.
Padding. Base64 emits four characters per three input bytes, so inputs whose length is not a multiple of three are padded to keep the output length a multiple of four.
A variant from RFC 4648 section 5 that replaces + with - and / with _, because the standard characters have meaning inside URLs. Padding is often dropped as well. JSON Web Tokens use this variant.
About 33%, plus padding. Four output characters for every three input bytes, before any line-break overhead.
This panel encodes text. For binary files, encode the bytes with a tool that reads the file directly, otherwise the character encoding step will corrupt the data.
Go deeper