RFC 4648 Base64 and Base64urlReviewed 29 Sep 2026Runs in your browser

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.

Who wrote it

Written by Suhaib Hassan. Figures are estimates you can edit. Our methodology.

How the engine works

It converts your input to UTF-8 bytes and maps every 6 bits to a character of the Base64 alphabet, following RFC 4648.

Why we built it

Developers hit Base64 in tokens, headers, data URIs and email. This lets you check a value and see how it is built.

Input

0 bytes
Examples
Base64 output—
—

—

Input size—
Output size—
Size change—
Padding—
First characters, bit by biteach character is 6 bits
CharacterIndex6 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.

IndexStandard (RFC 4648 §4)URL-safe (§5)
0 to 25A to ZA to Z
26 to 51a to za to z
52 to 610 to 90 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 characters

Output 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 → none

Worked examples

Illustrative figures, each checked by hand. The first is the default setup.

Short text

Encode "Man".

"Man" = 4D 61 6E = 010011 010110 000101 101110 = TWFu

Padding

Encode "Ma" (two bytes).

one leftover group is padded: TWE=

Default

Encode "Hello, CalculatePilot!" (22 bytes).

22 bytes → 4 × ceil(22 ÷ 3) = 32 characters, with 2 padding characters: 22 mod 3 = 1, so ==

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

InputBase64URL-safe
ManTWFuTWFu
HelloSGVsbG8=SGVsbG8=
Hello, World!SGVsbG8sIFdvcmxkIQ==SGVsbG8sIFdvcmxkIQ==
user:passdXNlcjpwYXNzdXNlcjpwYXNz
caféY2Fmw6k=Y2Fmw6k=
€4oKs4oKs
😀 (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:pass becomes dXNlcjpwYXNz in 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"} becomes eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
  • JSON and XML: a way to carry binary data inside text formats.

Base64 vs hex: how much bigger?

Input sizeBase64Hex
100 bytes136 characters200 characters
1 KB (1,024 bytes)1,368 characters2,048 characters
10 KB (10,240 bytes)13,656 characters20,480 characters
1 MB (1,048,576 bytes)1,398,104 characters2,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.

All Everyday Calculators

Embed This Base64 Encode Decode

Free and responsive, and it runs in the visitor's browser. Branding removal from $7.99/month.

<iframe src="https://www.calculatepilot.com/embed/base64-encode-decode.html" width="100%" height="560" loading="lazy" title="Base64 Encode Decode"></iframe>
For website owners

Want this calculator on your own website?

Embed it in one line of code. Keep it free with a small CalculatePilot attribution link, or go white-label: your brand, no attribution, one license for all your domains.

  • All 159 calculators, unlimited embeds
  • Works on WordPress, Webflow, Squarespace, Wix and plain HTML
  • Runs in your visitor's browser, so nothing is sent to a server
  • License key emailed automatically after checkout, cancel anytime
$7.99 / month
or $89.99 / year · white-label Pro
Get the white-label license Embed free with attribution