Advertisement

Base64 Encoder / Decoder

Encode text or files to Base64, or decode Base64 back to plain text. Supports URL-safe Base64 and file-to-Base64 conversion.

0 chars / 0 bytes
0 chars / 0 bytes

What is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that represents binary data using 64 printable ASCII characters: A–Z, a–z, 0–9, and the symbols + and / (with = as padding). It was designed to safely transmit binary data — such as images, audio files, or encryption keys — through systems that were originally designed to handle only text, such as email (SMTP), HTTP headers, and XML. The name "Base64" comes from the fact that 64 characters are used as the encoding alphabet.

The encoding process works by grouping the input bytes into sets of 3 (24 bits total), then splitting each group into four 6-bit values, each mapped to one of the 64 characters. This means every 3 bytes of binary input becomes exactly 4 Base64 characters, resulting in approximately 33% size overhead compared to the original binary data. If the input length is not divisible by 3, = padding characters are added to make the output length a multiple of 4.

Base64 is not encryption — it is an encoding scheme, meaning anyone can decode it without a key. It is widely used in JWT tokens, email attachments (MIME), embedding images in HTML/CSS as data URLs, storing binary data in JSON, and HTTP Basic Authentication. URL-safe Base64 (Base64url) replaces + with - and / with _ to avoid conflicts with URL-reserved characters, and is used in JWTs and OAuth tokens.

Common Base64 Use Cases

Embed Image in HTML/CSS

Convert image files to Base64 data URLs to embed them directly in HTML img tags or CSS background-image properties — no separate file request.

data:image/png;base64,iVBORw0…

HTTP Basic Auth Header

HTTP Basic Authentication encodes credentials as Base64 in the Authorization header. The format is Base64("username:password").

Authorization: Basic dXNlcjpwYXNz

JWT Token Payload

JSON Web Tokens (JWT) use URL-safe Base64 encoding (Base64url) for the header and payload segments, separated by dots.

eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOi…

How the Base64 Encoder/Decoder Works

Formula, assumptions, and calculation steps for this dev tools tool.

Formula Used

Encodes 3 bytes of input into 4 Base64 characters using the standard 64-character alphabet

Methodology

Groups input bytes into 3-byte blocks and maps each 6-bit segment to a character in the standard Base64 alphabet, or reverses the process to decode.

Calculation Steps

  1. Provide the input text or select generation options.
  2. Apply the selected encoding, parsing, hashing, or formatting rule.
  3. Validate the output where possible.
  4. Return copy-ready developer output.

Assumptions and Limits

  • Generated or transformed output depends exactly on the supplied input.
  • Security-sensitive values should be handled carefully.
  • Browser tools do not replace production validation.

Frequently Asked Questions

Base64 is a binary-to-text encoding scheme that represents binary data using 64 printable ASCII characters (A-Z, a-z, 0-9, +, /). It is used to transmit binary data over channels that only support text, such as email (MIME), JSON APIs, and HTML attributes.

Standard Base64 uses + and / characters, which have special meaning in URLs. URL-safe Base64 (Base64url) replaces + with - and / with _, making the output safe to include in URLs and HTTP headers without percent-encoding. JWT tokens use Base64url encoding.

Base64 encodes every 3 bytes of input as 4 ASCII characters (a 4/3 ratio). This means Base64 output is always approximately 33% larger than the original binary data. Padding characters (=) are added to make the output length a multiple of 4.

No. Base64 is an encoding scheme, not encryption. It is trivially reversible — anyone can decode Base64 without a key. It is used for format compatibility, not security. Never use Base64 to hide sensitive data.

Real-World Applications of Base64 Encoding

🔐
HTTP Basic Authentication
HTTP Basic Auth encodes "username:password" in Base64 in the Authorization header. This is encoding, not encryption — always use HTTPS to protect the credentials.
🖼️
Inline Images in HTML/CSS
Embed small images directly in HTML or CSS as Base64 data URLs to eliminate extra HTTP requests and simplify single-file deployments.
📧
Email Attachments (MIME)
Email protocols transmit only ASCII text. MIME encodes file attachments as Base64 so binary files (PDFs, images) survive transmission through mail servers.
🔑
JWT (JSON Web Tokens)
JWT headers and payloads are Base64url-encoded JSON. Decoding reveals the token claims — JWTs are signed, not encrypted, so the payload is readable by anyone.
💾
Binary Data in JSON/XML
JSON and XML are text formats. Binary data (encryption keys, file content, images) must be Base64-encoded to be safely embedded in these text-based document formats.
🔒
Cryptography Key Exchange
PEM format (used for SSL/TLS certificates and SSH keys) encodes binary DER certificate data as Base64 with header/footer lines for human-readable, text-safe transmission.

Common Base64 Mistakes to Avoid

1
Treating Base64 as Encryption
Base64 is encoding, not encryption. Anyone can decode a Base64 string without a key. Never use Base64 alone to protect sensitive data — use proper encryption like AES-256.
2
Using Standard Base64 in URLs
Standard Base64 uses + and / which are reserved in URLs. Use Base64url (replaces + with - and / with _) for URL parameters, OAuth tokens, and JWT values.
3
Ignoring the 33% Size Overhead
Base64 increases data size by ~33%. Embedding large images as Base64 in HTML significantly increases page weight — use a CDN and direct image URLs for images larger than ~10 KB.
4
Forgetting Character Encoding Before Base64
Base64 encodes bytes, not characters. If your text contains non-ASCII characters (emoji, accented letters), ensure it is UTF-8 encoded before Base64 encoding to avoid incorrect output.
5
Assuming Padding (=) is Always Required
Standard Base64 requires = padding to make output length a multiple of 4. Some implementations (Base64url in JWT) omit padding. Always check which variant is expected by the receiving system.

References

  1. IETF RFC 4648. The Base16, Base32, and Base64 Data Encodings. tools.ietf.org/html/rfc4648
  2. IETF RFC 7519. JSON Web Token (JWT). tools.ietf.org/html/rfc7519
  3. IETF RFC 2045. MIME Part One: Format of Internet Message Bodies. tools.ietf.org/html/rfc2045
  4. MDN Web Docs. Base64 encoding and decoding. developer.mozilla.org
  5. IETF RFC 7617. The 'Basic' HTTP Authentication Scheme. tools.ietf.org/html/rfc7617