Base64 Encoder / Decoder
Convert text to Base64 or decode Base64 back to readable text. Everything runs in your browser, so the input never leaves the page.
Base64 output
Encoded output uses only the 64 Base64 symbols plus padding; decoded output is shown as readable UTF-8 text.
Encoded size at a glance
| Input | Base64 characters | Growth |
|---|---|---|
| 3 bytes | 4 | 33% larger |
| 100 bytes | 136 | 36% larger |
| 1 KB (1,024 bytes) | 1,368 | 34% larger |
| 10 KB (10,240 bytes) | 13,656 | 33% larger |
| 1 MB (1,048,576 bytes) | 1,398,104 | 33% larger |
Calculated with 4 × ceil(bytes ÷ 3). Line breaks in MIME output add a few more characters.
Base64 is a transport format, not a security feature
Base64 exists so binary data can pass through channels that only accept printable text. It changes the representation of the bytes, not their meaning, and anyone holding the string can turn it back into the original.
How Base64 encoding works
The alphabet contains 64 characters: A–Z (26), a–z (26), 0–9 (10), plus + and /. Because 64 equals 26, every character represents exactly six bits.
The encoder reads the input three bytes at a time. Three bytes are 24 bits, and 24 divides evenly into four groups of six. Each group selects one alphabet character, so three bytes in become four characters out. The mapping is fixed and public, which is why the same input always encodes to the same string.
When the input length is not a multiple of three, the last group is padded with zero bits and the missing bytes are marked with =. One leftover byte yields two characters followed by ==; two leftover bytes yield three characters followed by a single =.
encoded characters = 4 × ceil(input bytes ÷ 3)
Check it by hand: Hi! is the byte sequence 0x48 0x69 0x21. In binary that is 01001000 01101001 00100001, regrouped as 010010 000110 100100 100001 = 18, 6, 36, 33. Those indexes land on S, G, k, h, so the result is SGkh. A five-byte word such as Hello needs padding and becomes SGVsbG8=.
Why Unicode text needs extra care
JavaScript's btoa() expects a binary string: every character code must be 255 or lower. Passing accented letters, curly quotes, emoji or non-Latin scripts straight into it throws an InvalidCharacterError, which is the most common reason a Base64 tool "works for English but fails for everything else".
The script on this page converts the string to UTF-8 bytes first using encodeURIComponent(), then hands those bytes to btoa(). Decoding reverses the route: atob() rebuilds the byte string and decodeURIComponent() interprets it as UTF-8.
That detail explains a frequent surprise. café stored as UTF-8 encodes to Y2Fmw6k=, while the same word stored in a legacy Windows code page encodes to something different. If two systems disagree about the encoding of the source bytes, they will disagree about the Base64 too.
Where Base64 shows up in real systems
| Usage | What is encoded | Why Base64 |
|---|---|---|
| Data URI | Small images, fonts, icons | Lets HTML or CSS carry the asset in one request |
| JSON payload | Files or binary fields | JSON strings cannot hold raw bytes |
| HTTP Basic auth | Username and password | The header value must be visible ASCII |
| Email attachments | Any file, MIME encoded | SMTP was designed for text |
| JWT segments | Header and claims JSON | Tokens travel in headers and URLs |
| PEM certificates | DER-encoded keys and certs | Text blocks survive copy and paste |
Basic authentication is the case people misread most often. The credentials are Base64, not encrypted, so the header is readable by anyone who can see the request. Transport encryption is what protects it, never the encoding itself.
Base64 vs encryption vs hashing
| Operation | Reversible? | Needs a key? |
|---|---|---|
| Base64 encoding | Yes, by anyone | No |
| Encryption | Only with the key | Yes |
| Hashing | No | No, but a salt is common |
URL-safe Base64, padding and line breaks
Standard Base64 uses + and /, which have reserved meanings inside URLs and file names. RFC 4648 defines a URL-safe variant that swaps them for - and _. Some systems also drop the = padding, because the decoder can reconstruct it from the string length. A JWT is the best-known example: its segments are Base64url without padding.
MIME email wraps encoded content at a fixed line length, so the same file can appear with hard line breaks every 76 characters. Those breaks are formatting, not data, but a strict decoder may reject them. This tool trims whitespace at both ends of the input before decoding, which covers the most common copy-and-paste case.
Typical failure messages and what they mean:
- Invalid character: the string contains a symbol outside the alphabet, often a stray quote or a data-URI prefix such as
data:image/png;base64,. - Incorrect length or padding: characters were dropped, or
=signs were removed from a decoder that requires them. - Garbled output: the decode succeeded but the bytes were never UTF-8 text, for example when decoding an encoded image.
Related Developer & Security Tools
| Tool | What does it do? | Action |
|---|---|---|
| Base64 Encoder & Decoder | Encode text to Base64 or decode a Base64 string back to plain text. | Current Page |
| Hash Generator | Create MD5, SHA-1, SHA-256 and SHA-512 hashes from text. | Hash Maker → |
| UUID Generator | Generate random UUID v4 values, one or many at a time. | UUID Maker → |
| Password Generator | Build strong random passwords with length and character options. | Password Maker → |
| Regex Tester | Test a regular expression against sample text and inspect the matches. | Regex Test → |
| JWT Decoder | Decode a JWT header and payload locally, without sending the token anywhere. | JWT Decode → |
Frequently Asked Questions
==, two leftover bytes produce a single =.data:text/plain;base64,, characters that belong to the URL-safe alphabet, or line breaks inserted by an email client. Remove the prefix and try the - and _ variant if the string came from a JWT or a URL.
Rate this Tool
Based on 0 user ratings.