How Base64 encoding works, bit by bit
Base64 turns any sequence of bytes into plain text that uses only 64 safe characters. It is an encoding, not encryption: anyone can reverse it. This page walks through the bit grouping by hand so the output stops looking like noise.
Encode or decode Base64
Why Base64 exists
Many older systems were built to carry text, not raw bytes. Email bodies, JSON strings, HTML attributes and HTTP headers can break or silently change when they meet a byte such as 0x00 or a line break in the wrong place. Base64 solves this by mapping every 3 bytes of input onto 4 characters drawn from a small, safe alphabet: A–Z, a–z, 0–9, + and /, with = for padding.
The price is size. Four characters for every three bytes means the encoded form is about one third larger than the original.
A 1,000-byte file becomes 4 × ceil(333.33) = 4 × 334 = 1,336 characters. A 3,000,000-byte image becomes exactly 4,000,000 characters.
Encoding “Hi!” by hand
- Turn the text into bytes. In ASCII and UTF-8,
His 0x48,iis 0x69 and!is 0x21. - Write each byte as 8 bits. 01001000 01101001 00100001. That is 24 bits in a row.
- Cut the 24 bits into four 6-bit groups. 010010 | 000110 | 100100 | 100001.
- Read each group as a number from 0 to 63. 18, 6, 36, 33.
- Look each number up in the alphabet. 0–25 are A–Z, 26–51 are a–z, 52–61 are 0–9, 62 is
+and 63 is/. So 18 = S, 6 = G, 36 = k, 33 = h.
Result: Hi! encodes to SGkh. Paste SGkh into the tool above and press Decode to check it.
Padding: what the equals signs mean
When the input length is not a multiple of 3, the last group is short. The encoder fills the missing bits with zeros and adds = so the output length stays a multiple of 4.
| Input | Bits (with zero fill) | 6-bit values | Output |
|---|---|---|---|
Hi! (3 bytes) | 010010 000110 100100 100001 | 18, 6, 36, 33 | SGkh |
Hi (2 bytes) | 010010 000110 100100 | 18, 6, 36 | SGk= |
H (1 byte) | 010010 000000 | 18, 0 | SA== |
One = means the last block held 2 real bytes. Two == means it held 1. Some formats drop the padding because the decoder can work it out from the length.
Non-English text and UTF-8
Base64 works on bytes, so text must first become bytes. The letter é is two bytes in UTF-8, 0xC3 0xA9, and encodes to w6k=. The browser function btoa() only accepts characters below 256, so btoa("é") gives a different, Latin-1 based answer, and btoa fails on an emoji. The tool on this page converts text to UTF-8 bytes first with TextEncoder, which is the safe approach.
URL-safe Base64
The + and / characters have special meaning in URLs and file names. The URL-safe variant swaps them for - and _ and usually drops the padding. The bytes 0xFB 0xFF encode to +/8= in standard Base64 and to -_8 in the URL-safe form. JSON Web Tokens use the URL-safe form for all three parts.
Common mistakes
- Treating Base64 as security. It hides nothing. Never “protect” a password or API key by encoding it.
- Mixing the two alphabets. A decoder that expects
+/rejects-_. Convert first, as this tool does. - Line breaks inside the data. Older email encoders wrap lines at 76 characters. Strip whitespace before you decode.
- Encoding twice. If the output starts with something like
U0dr, you may have encoded text that was already Base64.
Questions
Can I decode an image with this page?
The tool decodes to text. If the bytes are an image or another binary file, it tells you the result is not valid UTF-8 instead of showing garbage.
Is my input sent anywhere?
No. Encoding and decoding run in your browser. Nothing is uploaded or stored.
Why is the output longer than the input?
Each character of output carries only 6 bits instead of 8, so you need 4 characters for every 3 bytes.