Base64 Encoder & Decoder
Encode text or hex bytes to Base64 and decode Base64 back to text or bytes. It supports the URL-safe alphabet, optional padding and 76-character MIME line wrapping, and shows how the bits map to characters.
Written by Suhaib Hassan. Figures are estimates you can edit. Our methodology.
It converts your input to UTF-8 bytes and maps every 6 bits to a character of the Base64 alphabet, following RFC 4648.
Developers hit Base64 in tokens, headers, data URIs and email. This lets you check a value and see how it is built.
—
| Character | Index | 6 bits |
|---|
The Base64 alphabet
Base64 uses 64 printable characters. Three bytes (24 bits) become four characters of 6 bits each. If the input is not a multiple of three bytes, = padding fills the last group.
| Index | Standard (RFC 4648 §4) | URL-safe (§5) |
|---|---|---|
| 0 to 25 | A to Z | A to Z |
| 26 to 51 | a to z | a to z |
| 52 to 61 | 0 to 9 | 0 to 9 |
| 62 | + | − (hyphen) |
| 63 | / | _ (underscore) |
| Padding | = | = or omitted |
Formulas
How the numbers are worked out.
Three bytes to four characters
Bytes are read as a stream of bits and cut into 6-bit groups, each mapped to one alphabet character.
24 bits = 3 bytes = 4 charactersOutput length
Every 3 input bytes give 4 characters, rounded up, with padding to fill.
length = 4 × ceil(bytes ÷ 3)
overhead ≈ 33%Padding
One leftover byte adds ==, two leftover bytes add =.
bytes mod 3 = 1 → "==", = 2 → "=", = 0 → noneWorked examples
Illustrative figures, each checked by hand. The first is the default setup.
Short text
Encode "Man".
Padding
Encode "Ma" (two bytes).
Default
Encode "Hello, CalculatePilot!" (22 bytes).
How to encode and decode Base64
- Choose Encode or Decode.
- Paste your text, or hex bytes.
- Set the URL-safe, padding and line wrapping options.
- Copy the output, or use it as the next input to check a round trip.
Base64 is an encoding, not encryption. Anyone can decode it, so never use it to hide secrets.
By Suhaib Hassan · Reviewed 29 September 2026 · How CalculatePilot verifies formulas →
Sources
- IETF, RFC 4648, The Base16, Base32, and Base64 Data Encodings (2006).
- IETF, RFC 2045, MIME Part One, section 6.8.
- IETF, RFC 7515, JSON Web Signature, Base64url without padding.
Common values to check against
| Input | Base64 | URL-safe |
|---|---|---|
| Man | TWFu | TWFu |
| Hello | SGVsbG8= | SGVsbG8= |
| Hello, World! | SGVsbG8sIFdvcmxkIQ== | SGVsbG8sIFdvcmxkIQ== |
| user:pass | dXNlcjpwYXNz | dXNlcjpwYXNz |
| café | Y2Fmw6k= | Y2Fmw6k= |
| € | 4oKs | 4oKs |
| 😀 (emoji) | 8J+YgA== | 8J-YgA== |
Text is first turned into UTF-8 bytes, so an accented letter takes 2 bytes, the euro sign 3 and an emoji 4. The last row is the only one where the URL-safe alphabet changes a character.
Where Base64 is used
- Data URIs: small images or fonts embedded in HTML or CSS as
data:image/png;base64,.... - Email (MIME): attachments are Base64 with lines wrapped at 76 characters (RFC 2045).
- HTTP Basic authentication:
user:passbecomesdXNlcjpwYXNzin the Authorization header. It is encoding, not protection. - JWTs: the header and payload use URL-safe Base64 without padding, for example
{"alg":"HS256","typ":"JWT"}becomeseyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. - JSON and XML: a way to carry binary data inside text formats.
Base64 vs hex: how much bigger?
| Input size | Base64 | Hex |
|---|---|---|
| 100 bytes | 136 characters | 200 characters |
| 1 KB (1,024 bytes) | 1,368 characters | 2,048 characters |
| 10 KB (10,240 bytes) | 13,656 characters | 20,480 characters |
| 1 MB (1,048,576 bytes) | 1,398,104 characters | 2,097,152 characters |
Base64 adds about 33% and hex adds 100%, before any line breaks.
Why a decode fails
- The text contains characters outside the alphabet, such as spaces or a stray quote.
- The length is wrong: a valid unpadded length can never leave exactly 1 character in the last group.
- The input is URL-safe (- and _) but decoded as standard, or the other way round.
- Padding was removed. Add = until the length is a multiple of 4, or tick the URL-safe option.
- The bytes are not valid UTF-8 text, for example an image. Decode them as hex bytes instead.
Frequently asked questions
What is Base64 used for?
Carrying binary data through text-only systems, such as email attachments, data URIs, JSON tokens (JWT) and HTTP Basic authentication headers.
Is Base64 encryption?
No. It only re-writes bytes with a different alphabet. Anyone can decode it.
Why does the output end with =?
Padding. Base64 works in groups of 3 bytes. When the input is not a multiple of 3, one or two = characters complete the last group.
What is URL-safe Base64?
A variant that uses - and _ instead of + and /, so it can sit in URLs and file names. JWTs also leave off the = padding.
Why is the output bigger?
Every 3 bytes become 4 characters, about 33% larger, plus line breaks if you wrap lines.
Is Base64 larger than hex?
No, it is smaller. Base64 grows data by about 33% (3 bytes become 4 characters) while hex doubles it (1 byte becomes 2 characters). A 1 KB input is 1,368 Base64 characters or 2,048 hex characters.
Why does my Base64 decode fail?
Usual causes are characters outside the alphabet, a wrong length, missing padding, mixing URL-safe and standard alphabets, or bytes that are not valid UTF-8 text such as an image.
Does it handle UTF-8, accents and emoji?
Yes. Text is converted to UTF-8 bytes first, so cafe with an accent encodes to Y2Fmw6k= and the grinning-face emoji to 8J+YgA==.
How does Base64 work in HTTP Basic authentication?
The username and password joined by a colon are Base64-encoded, so user:pass becomes dXNlcjpwYXNz. Anyone can decode it, so use HTTPS and never treat it as security.
How much bigger does an image become as a data URI?
About 33% bigger as Base64. A 10 KB image (10,240 bytes) becomes 13,656 characters, plus the data URI prefix.
Related calculators
More everyday tools.