Skip to main content
UtilitiesFree · no sign-up

Base64 Encoder and Decoder

Encode text to Base64 or decode it back, with the URL-safe alphabet as an option.

Updated

Everything runs in your browser. Nothing is uploaded, logged, or written into the page URL, and Base64 is an encoding rather than encryption, so anyone who has the output can read it back.

Base64 output

QmFzZTY0IGlzIGFuIGVuY29kaW5nLCBub3QgZW5jcnlwdGlvbi4g8J+YgCDZhdix2K3YqNin

Input, in UTF-8 bytes
54
Output characters
72
Size change
+33.3%

Base64 is not encryption and not a password. It is a way to carry bytes through a channel that only accepts text, and anyone can reverse it in one step. Do not use it to hide an API key, a token, or anything else that has to stay secret.

In short

How much bigger does Base64 make something?

About 33 percent. Base64 turns every 3 bytes of input into 4 characters of output, so the length is ceil(bytes ÷ 3) × 4. A 1,024 byte file becomes 1,368 characters and a 1 MB file becomes 1,398,104. Short strings pay far more: a single byte still costs the full 4 characters, a 300 percent increase.

Base64 is an encoding, not encryption. Anyone holding the output can turn it back into the original in one step, so it hides nothing from anybody.

How to use the base64 encoder and decoder

Paste into the box on the left and the result updates on every keystroke. Encoding reports the UTF-8 byte count of your input, the character count of the output, and the percentage difference between them. Decoding reports the byte count that came back and which alphabet it found.

Unicode is where most encoders break. The browser function btoa() only accepts characters up to U+00FF, so a single emoji or one Arabic word makes it throw. This tool converts your text to UTF-8 bytes first and encodes the bytes, which is the only approach that survives real input.

4 : 3

Characters per byte

6 bits per character

+33%

Size cost at scale

1 MB becomes 1,398,104 chars

64 + 1

Alphabet size

64 symbols plus the = padding

The size cost is fixed and worth planning around. Four output characters carry 24 bits, which is exactly 3 input bytes, so the output is always the input rounded up to the next multiple of 3 and then multiplied by four thirds. That is why an inline image in a stylesheet is a third larger than the file on disk.

Decoding here is deliberately forgiving about the harmless things. Line breaks are stripped, because MIME wrapped Base64 at 76 columns for decades. Both alphabets are accepted. Missing padding is added back. What it will not do is guess: an unknown character or an impossible length gets a reason, not a truncated answer.

Nothing you paste leaves your browser. There is no upload, no server round trip, no logging, and the text is never written into the page URL, so no shareable link quietly carries it away. That matters more here than on most pages, because the strings people bring to a Base64 tool are so often credentials.

Do

  • Use the URL-safe alphabet whenever the output goes into a link or filename.
  • Convert text to UTF-8 bytes before encoding, which this tool does for you.
  • Budget a 33 percent size increase wherever the encoded value is stored.
  • Treat a decoded token as exposed the moment it appears on any screen.
  • Send binary as Base64 only when the channel genuinely cannot carry bytes.

Don't

  • Store a password or an API key in Base64 and call it protected.
  • Assume btoa handles an emoji or an Arabic string, because it throws.
  • Paste a live production secret into any web tool, including this one.
  • Expect Base64 to compress anything: it only ever grows the payload.
  • Feed standard Base64 straight into a query string without escaping plus and slash.

What Base64 costs at each input size, with and without the trailing equals padding.

Input bytesBase64 charactersWithout paddingSize change
142+300%
243+100%
344+33.3%
101614+60.0%
100136134+36.0%
1,0001,3361,334+33.6%
1,024 (1 KiB)1,3681,366+33.6%
10,240 (10 KiB)13,65613,654+33.4%
1,048,576 (1 MiB)1,398,1041,398,102+33.3%
Computed with the same encoder this page runs: padded length is ceil(bytes ÷ 3) × 4, unpadded is ceil(bytes × 4 ÷ 3). Sizes shown as bytes, since Base64 encodes bytes rather than characters.

Why Base64 keeps getting mistaken for security

The confusion is understandable. Base64 output looks scrambled, it is full of capital letters and digits, and it appears in the same places real cryptography does: authorization headers, config files, JSON Web Tokens. Looking unreadable to a human is not the same as being unreadable to anyone, and that gap is where the mistake lives.

The Base 64 encoding is designed to represent arbitrary sequences of octets in a form that allows the use of both upper- and lowercase letters but that need not be human readable.
S. Josefsson, RFC 4648 section 4, The Base16, Base32, and Base64 Data Encodings, October 2006

The standard describes a transport format and never claims confidentiality. A JSON Web Token makes the point well: its header and payload are Base64url, plainly readable by anyone, and only the signature at the end proves the token was not tampered with. The parts you can read were never meant to be secret.

  • Need the contents hidden? Encrypt them, then Base64 the ciphertext if the channel needs text.
  • Need to prove nothing was altered? Sign or use a message authentication code.
  • Need to store a password? Hash it with bcrypt, scrypt or Argon2, never encode it.
  • Need to move bytes through a text-only field? That is the job Base64 actually does.

One practical consequence: a secret that has been Base64 encoded and pasted into a chat, a ticket or a log line is a leaked secret. Rotate it. The encoding buys no time at all, because reversing it takes one command and no key.

Standard alphabet or the URL-safe one?

The two alphabets differ in exactly two characters. Section 4 of RFC 4648 defines the standard set, which ends in plus and slash. Section 5 defines the URL and filename safe set, which uses hyphen and underscore in their place. The first 62 characters, the letters and digits, are identical in both.

What changes between the two
Value 62
+ becomes -
Value 63
/ becomes _
Padding
= required in section 4, optional in section 5
Everything else
identical, A to Z then a to z then 0 to 9

Both alphabets decode to the same bytes, so a value encoded one way and decoded the other is safe as long as the decoder handles both, which this one does.

The reason to care is what plus and slash mean elsewhere. A slash splits a path segment, and a plus is read as a space by anything parsing form-encoded data. Put standard Base64 in a query string without escaping it and a value containing a plus comes back with a space where the plus was.

Padding is the other difference. The equals signs exist so a decoder knows the output length without being told, but they also need escaping in a URL as %3D. Section 5 therefore allows them to be omitted when the length is known from context, which is why most token formats leave them off.

Escaping a value for a query string

If the encoded value still has to survive a URL, percent-encoding is the next step and the component rule is the one you want.

Open the URL encoder

The formula, worked line by line

Base64 is a regrouping, not a calculation. Take the input as a stream of bits, cut it every 6 bits instead of every 8, and read each 6-bit group as a number from 0 to 63. That number picks one character out of the 64 character alphabet, and the whole scheme falls out of that one move.

Six and eight have a lowest common multiple of 24, which is why the unit of work is 3 bytes in and 4 characters out. When the input does not divide by 3 the last group is padded with zero bits and the output is padded with equals signs, so the decoder can tell how many real bytes the final group held.

output characters = ceil(input bytes ÷ 3) × 4
output characters without padding = ceil(input bytes × 4 ÷ 3)
size change = output characters ÷ input bytes − 1
4 characters × 6 bits = 24 bits = 3 bytes
Three bytes regrouped into four Base64 charactersThe three letters Man are 77, 97, 110 as bytes, which is 24 bits. Base64 cuts those same 24 bits every 6 bits instead of every 8, giving four values of 0 to 63 that map to the characters T, W, F, u. That is why every 3 bytes of input become 4 characters of output, about 33 percent larger.3 BYTES = 24 BITS = 4 CHARACTERSM0100110177a0110000197n0110111011001001119T01011022W0001015F10111046ueach 6-bit group indexes one of 64 characters, so nothing is hiddenTHE SIZE COSTinput bytes3output characters41 KB becomes1,368 charsgrowth+33.3%
The same 24 bits, cut every 8 bits as bytes and every 6 bits as Base64 characters.
The three letters Man, byte by byte
M, a, n as bytes
77, 97, 110
The same 24 bits
01001101 01100001 01101110
Cut every 6 bits
010011 010110 000101 101110
As numbers 0 to 63
19, 22, 5, 46
Alphabet lookup
T W F u

Three bytes in, four characters out, no padding needed because 3 divides by 3. The RFC 4648 section 10 vectors check the ragged cases: f is Zg==, fo is Zm8=, and foo is Zm9v.

The padding tells the decoder how much of the last group was real. One equals sign means the final 4 characters carried 2 bytes, two equals signs mean they carried 1 byte, and no padding means a full 3. Without that marker a decoder could not distinguish a trailing zero byte from an absent one.

That is also why a Base64 string can never have a length of exactly one more than a multiple of four. Four characters carry three bytes, three characters carry two, two characters carry one, and one character on its own carries nothing at all. A remainder of one is a truncated string, and this tool says so.

Data URIs are the size cost made visible. An inline image in a stylesheet is roughly a third larger than the file it replaces, which can still be the right trade for a small icon that would otherwise cost a network request, and is rarely right for a photograph.

Questions people ask

Sources

Where the constants and formulas on this page come from. Each line names the figure it backs.

  1. Values 62 and 63 are + and / in the standard alphabet but - and _ in the URL and filename safe alphabet, and the = padding may be omitted when the length is known.

    RFC 4648: The Base16, Base32, and Base64 Data EncodingsIETF, 2006