How Base64 works
Base64 takes the input bytes three at a time (24 bits) and splits them into four 6-bit groups. Each group indexes the alphabet A–Z a–z 0–9 + /. If the input length is not a multiple of three, = padding fills the last block. The output is always about 4/3 the size of the input.
encoded length = 4 × ⌈bytes ÷ 3⌉
Worked example
"Man" is the bytes 77, 97, 110 → binary 01001101 01100001 01101110 → groups 19, 22, 5, 46 → TWFu.
| Text | Base64 | Note |
|---|---|---|
| M | TQ== | 1 byte → 2 padding chars |
| Ma | TWE= | 2 bytes → 1 padding char |
| Man | TWFu | 3 bytes → no padding |
| é | w6k= | UTF-8 uses 2 bytes for é |
Base64 vs base64url
The URL-safe variant (RFC 4648 §5) replaces + with - and / with _, and usually drops padding. JWTs use base64url. The decoder here accepts both.
Base64 is not encryption
Anyone can decode Base64. Use it to move binary data through text-only channels (email, JSON, HTML), never to hide secrets.