AI Learning GymAI Learning Gym

Free developer tools

← Back to Dashboard

Base64 Encoder / Decoder

Plain Text (or Base64 to decode)
Result

About Base64

Base64 is a way to represent binary data — or any text — using only 64 safe characters (letters, numbers, +, /, and =). It's widely used to send data through systems that only handle plain text safely.

How to use this tool

  1. To encode: paste plain text in the left box and click Encode to Base64.
  2. To decode: paste a Base64 string in the left box and click Decode from Base64.
  3. Click Copy Result to copy the output to your clipboard.

What is Base64 used for?

You'll encounter Base64 in many common situations:

Is Base64 encryption?

No — and this is a common misconception. Base64 is encoding, not encryption. Anyone with a Base64 decoder (including this tool) can read the original text instantly. It's designed for safe data transport, not security. Never use Base64 to "hide" passwords or sensitive information.

Why does Base64 output end with = signs?

Base64 works in chunks of 3 bytes at a time. When the input isn't a multiple of 3 bytes, padding characters (= or ==) are added to fill the last chunk. This is normal and expected — it doesn't mean anything is wrong.

Frequently asked questions

Is my data stored or sent anywhere?

No. All encoding and decoding happens in your browser using JavaScript. Nothing is uploaded or logged. You can use it safely with sensitive content.

Why is the encoded output longer than the original?

Base64 uses 4 characters to represent every 3 bytes of input, so the output is roughly 33% larger. That's the trade-off for using only safe, printable characters.

Can I use this for encoding files or images?

This tool handles plain text. For encoding binary files or images, you would need a tool that reads the raw bytes of the file and encodes them — text-based Base64 tools like this one work with UTF-8 text strings only.

What's URL-safe Base64?

Standard Base64 uses + and /, which have special meanings in URLs. URL-safe Base64 replaces those with - and _ instead, making it safe to include in web addresses without encoding. This tool uses standard Base64.

How Base64 Encoding Works

Base64 encoding follows a specific mathematical process that converts any binary data into a string of printable ASCII characters. Understanding how it works explains why the output looks the way it does and why the encoded result is always longer than the original input.

The 64-Character Alphabet

Base64 gets its name from the 64 characters it uses to represent all possible data. These characters are deliberately chosen because they are safe to use in virtually every text-based system — email, HTTP headers, HTML, XML, and URLs (with minor variations).

The Encoding Process Step by Step

Base64 converts data in groups of 3 bytes at a time. Each group of 3 bytes (24 bits) is split into four 6-bit chunks. Each 6-bit chunk maps to one of the 64 characters in the Base64 alphabet. This is why Base64 output is always 4 characters for every 3 bytes of input — producing output that is approximately 33% larger than the original.

Here is a concrete example encoding the word "Man":

You can verify this yourself — paste "Man" into the encoder above and click Encode. The result will be TWFu.

Understanding the Padding Characters

Because Base64 works in groups of 3 bytes, what happens when your input is not a multiple of 3 bytes? Padding solves this problem. If the input has one leftover byte, two = characters are appended. If it has two leftover bytes, one = is appended. If it is exactly divisible by 3, no padding is needed.

This is why Base64 strings often end in one or two equals signs — it is not an error, it is the padding that makes the output length always a multiple of 4 characters. Some implementations omit the padding (called "unpadded Base64"), which is common in URL-safe variants.

Real-World Uses of Base64

Base64 appears constantly in modern software development. Once you know what to look for, you will start recognizing it in places you never noticed before. Here are the most important real-world use cases every developer should understand.

JSON Web Tokens (JWT)

JSON Web Tokens are the most common authentication mechanism in modern web applications. A JWT consists of three parts separated by dots — the header, the payload, and the signature. Both the header and payload are Base64-encoded JSON objects. This allows the token to safely carry structured data through HTTP headers and URL parameters without encoding issues.

If you have ever inspected a JWT token, you will notice the first two sections look like a long string of letters and numbers ending with one or two equals signs. Pasting either section into this decoder will reveal the original JSON data. Note that JWTs use URL-safe Base64 (with - and _ instead of + and /), so you may need to substitute those characters before decoding.

HTTP Basic Authentication

When a web server uses Basic Authentication, the browser sends an Authorization header with every request. That header contains the username and password encoded in Base64 in the format username:password. The header looks like: Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=. You can decode that Base64 string and see the credentials immediately — which is exactly why Basic Auth should only be used over HTTPS, never plain HTTP. The encoding provides zero security on its own.

Embedding Images in HTML and CSS

Instead of linking to an external image file, you can embed the image data directly in your HTML or CSS using a Base64 data URI. The format looks like: src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...". This technique eliminates an additional HTTP request for small icons and images, which can improve page load performance. However, because Base64 encoding increases file size by 33%, it is only beneficial for small images — large images encoded this way will slow the page down rather than speed it up.

Email Attachments and MIME Encoding

Email was originally designed to carry only 7-bit ASCII text. Modern email attachments — PDF files, images, Word documents — are binary files that cannot be transmitted directly through this system. The MIME standard (Multipurpose Internet Mail Extensions) solves this by encoding binary attachments as Base64 text. When your email client receives a message with attachments, it is decoding Base64 behind the scenes before presenting the file to you. Base64 is what makes email attachments technically possible.

API Responses with Binary Data

REST APIs primarily exchange data as JSON, which is a text format. When an API needs to include binary data — a generated image, an audio file, a PDF document — in a JSON response, it typically encodes that data as Base64. The JSON field containing the file looks like a very long string of characters rather than the actual file bytes. Client applications decode the Base64 string back to binary before saving or displaying the file.

CSS Background Images

In addition to the HTML src attribute, Base64 data URIs work in CSS for background images: background-image: url("data:image/svg+xml;base64,..."). This is particularly common with SVG icons and small decorative elements where inlining the image eliminates an HTTP request and ensures the image is always available regardless of external resource loading.

Configuration Files and Environment Variables

Configuration files and environment variables often need to contain values that include special characters — newlines, quotes, colons — that would break the file format. Encoding these values as Base64 produces a clean alphanumeric string that can be safely stored in any configuration format and decoded at runtime by the application. This is a common pattern for storing certificates, private keys, and multi-line configuration values in environment variables for containerized applications.

Base64 vs Other Encoding Methods

Base64 is the most widely used binary-to-text encoding, but it is not the only one. Understanding the alternatives helps you choose the right encoding for your specific situation.

Base64 vs Hexadecimal

Hexadecimal encoding (hex) represents each byte as two characters from 0–9 and A–F. It is simpler than Base64 and easier to read when inspecting individual bytes, but it is less efficient — hex output is twice the size of the input, while Base64 output is only 33% larger. Hex is commonly used for cryptographic hashes (like MD5 and SHA-256 checksums), color codes in web design, and memory addresses in debugging. Base64 is preferred when file size matters or when the encoded output must fit in a JSON string or HTTP header.

Base64 vs Percent Encoding (URL Encoding)

Percent encoding (also called URL encoding) is the standard for representing special characters in URLs. A space becomes %20, an ampersand becomes %26, and so on. Unlike Base64 which encodes entire files or strings into a new format, percent encoding is designed specifically for URLs and only encodes characters that are not safe in a URL context. Base64-encoded strings can be further percent-encoded when used in URLs — this double encoding is common when passing tokens as query parameters.

Base64 vs Binary

Raw binary data is the most efficient representation — it uses the exact minimum bytes needed without any overhead. However, binary data cannot be safely transmitted through text-based systems because many protocols and file formats interpret certain byte values as control characters. Base64 is the solution when you need to transport binary data through a text-based channel. When binary channels are available — direct file uploads, binary WebSocket frames, binary protocol buffers — raw binary is always more efficient than Base64.

Standard Base64 vs URL-Safe Base64

Standard Base64 uses + and / as the 63rd and 64th characters. These characters have special meanings in URLs — + represents a space and / is a path separator. URL-safe Base64 (also called Base64url) substitutes - for + and _ for /, making the encoded output safe to include directly in URLs and filenames without percent-encoding. JWT tokens use URL-safe Base64. When you need to include Base64 data in a URL, use URL-safe Base64 or percent-encode the standard output.

Common Base64 Mistakes and How to Fix Them

Base64 decoding errors are common and usually straightforward to diagnose. Here are the most frequent problems developers encounter and how to resolve them.

Invalid Character Error

This error occurs when the input contains characters that are not in the Base64 alphabet. The most common causes are whitespace (spaces, newlines, tabs) that was accidentally included when copying the string, or URL-safe Base64 characters (- and _) being passed to a standard Base64 decoder. Fix: remove all whitespace from the input and replace - with + and _ with / before decoding.

Incorrect Padding Error

Base64 strings must have a length that is a multiple of 4. If a Base64 string was truncated, modified, or had its padding characters removed, the decoder will fail with a padding error. Fix: add = characters to the end of the string until its length is a multiple of 4. If the string length mod 4 is 2, add two = characters. If it is 3, add one =.

Unicode Characters Not Decoding Correctly

Standard Base64 encoding in JavaScript handles ASCII characters natively but requires special handling for Unicode characters (emojis, accented characters, non-Latin scripts). If you encode a string containing Unicode characters and the result does not decode correctly, the encoding step needs to handle the character set conversion explicitly. This tool handles Unicode correctly by using UTF-8 encoding before the Base64 conversion.

Confusing Encoding with Encryption

This is not a technical error but a conceptual one that creates security vulnerabilities. Base64 is reversible by anyone with a decoder — it provides no confidentiality whatsoever. Never store passwords, API keys, or other sensitive data in Base64 and consider it protected. Use proper encryption (AES, RSA) for data that must be kept confidential, and use cryptographic hashing (bcrypt, SHA-256) for passwords.