How to use this calculator
- 1 Choose Encode text, or Decode Base64.
- 2 Paste your text, or the Base64 string, into the box. Line breaks in Base64 are ignored.
- 3 For a web address or a token, tick the URL-safe alphabet to swap + and / for - and _.
- 4 Read the output and the size change. Encoding makes the text about a third longer.
What is Base64?
Base64 is a way to write binary data using only 64 plain characters: the letters A to Z and a to z, the digits 0 to 9, and the symbols + and /. The name comes from those 64 symbols. Base64 is defined in RFC 4648.
Some systems only handle text. Email, JSON and HTML can mangle raw bytes, such as an image or a binary key. Base64 turns those bytes into safe text, and turns the text back into the same bytes when it is decoded.
Base64 is an encoding, not encryption or compression. Anyone can decode it, so it does not protect secrets. Its only job is to change the form of the data.
How the encoding works
Each character holds 6 bits, because 2 to the power of 6 is 64. The input is read in groups of 3 bytes, which is 24 bits. Those 24 bits are split into four 6-bit pieces, and each piece becomes one character.
Because 3 bytes become 4 characters, the output is about 4 ÷ 3 times the input, or 33% longer. If the input is not a multiple of 3 bytes, the last group is padded with one or two = signs, so the output length is a multiple of 4.
For text, the bytes come from UTF-8, so accented letters and emoji use more bytes than plain English letters. The calculator shows both the byte count and the character count.
| Input bytes | Base64 characters | Padding |
|---|---|---|
| 3 | 4 | None |
| 2 | 4 | One = |
| 1 | 4 | Two == |
| 13 | 20 | Two == (the last group is 1 byte) |
URL-safe Base64 and where it is used
The standard alphabet uses + and /, which have special meanings in web addresses. The URL-safe variant, described in RFC 4648, replaces them with - and _. It also usually leaves out the = padding, so the string fits cleanly into a link or a file name. Percent-encoding, a different scheme for URLs, is covered by the URL encode and decode calculator.
Base64 appears in many places. Email attachments use it through MIME (RFC 2045), and web pages use it in data URIs (RFC 2397) to embed a small image inside a page. Authentication headers and JSON Web Tokens also use URL-safe Base64.
If you need to check what a Base64 string contains, decode it here. For the number systems used beside it, the binary calculator and the hex calculator show how bits and digits are written.
Tips for using Base64 correctly
Base64 is simple, but a few mistakes come up often. Keep these points in mind:
- Do not use it as security. It is easy to decode, so protect secrets with proper encryption instead.
- Expect the size increase. Base64 adds about a third, which matters for large payloads.
- Use the URL-safe form in links. Standard + and / characters can break a URL.
- Check the text encoding. Decode with the same character set the text was encoded with, usually UTF-8.
- Read the size change. For file sizes in data transfer, the bandwidth calculator shows the time needed.
The formula
Output length
characters = 4 × ⌈bytes ÷ 3⌉
- ⌈ ⌉
- round up to the next whole number
Size increase
output ÷ input ≈ 4 ÷ 3 ≈ 1.333, so about 33% longer for long inputs
Bits per character
2⁶ = 64 symbols, so each character carries 6 bits
- 6 bits
- the information in one Base64 character
Worked example
Encoding “Hello, World!”
- 1.Text to bytes: “Hello, World!” is 13 ASCII bytes.
- 2.Groups: 13 bytes = four groups of 3 bytes (16 characters) plus 1 leftover byte (2 characters and ==).
- 3.Total: 16 + 4 = 20 characters.
SGVsbG8sIFdvcmxkIQ==, which is 20 characters, about 54% longer than the 13-byte input.
Frequently asked questions
What is Base64 used for?
It carries binary data through text-only systems. Common uses include email attachments, data URIs in web pages, and tokens in authentication headers. It is an encoding, not a security measure.
Is Base64 encryption?
No. Base64 is reversible by anyone, with no key. To protect data, use encryption, and treat Base64 only as a way to store or send the encrypted bytes as text.
Why does Base64 end with = signs?
The = signs are padding. They fill the last group of four characters when the input is not a multiple of 3 bytes. The URL-safe form often leaves them out.
Why is my decoded text garbled?
The most common reason is the character set. Base64 stores bytes, and the text must be read as the right encoding, usually UTF-8. The string may also be corrupted or not Base64 at all.
How much bigger is Base64 than the original?
About one third bigger for long inputs. Every 3 bytes become 4 characters, so 300 bytes become about 400 characters.
Sources
Last reviewed by the GridCalculators team.