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.

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.

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