Base64 Encoder Decoder Online
Free online Base64 encoder and decoder. Instantly encode text to Base64 or decode Base64 to plain text. Supports URLs, files & images. No signup, 100% private, browser-based.
Base64 Encoder / Decoder
Copied ✅
Free Base64 Encoder Decoder Online – Encode & Decode Base64 Instantly
Instantly encode any text, URL, or data to Base64 format — or decode any Base64 string back to its original content. All processing happens locally in your browser. No data is sent to any server. Free, no signup required, works on any device.
[TOOL EMBED HERE — existing tool stays as is]
What Is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It converts binary data — which computers process as sequences of 0s and 1s — into a string of printable characters drawn from a set of 64 characters: the uppercase letters A through Z, the lowercase letters a through z, the digits 0 through 9, and the symbols + and /. The equals sign (=) is used as padding at the end of the encoded string when necessary.
The name “Base64” comes from the size of the character set used for encoding — 64 printable ASCII characters. Each Base64 character represents exactly 6 bits of binary data (since 2 to the power of 6 equals 64), which means three bytes of binary data (24 bits) are represented as four Base64 characters (24 bits divided into four 6-bit groups).
Base64 encoding was developed to solve a fundamental problem in data transmission — many communication systems and protocols were designed to handle only ASCII text, not arbitrary binary data. Email systems, HTTP headers, XML documents, and JSON structures are all fundamentally text-based. Base64 provides a reliable, universally supported way to represent any binary data — including images, files, audio, and encrypted content — as plain text that can be safely transmitted through these text-based systems without corruption.
How Does Base64 Encoding Work?
The Base64 encoding process works in three steps. First, the input data is divided into groups of three bytes (24 bits each). Second, each 24-bit group is divided into four 6-bit chunks. Third, each 6-bit chunk is mapped to its corresponding character in the Base64 alphabet — a lookup table that maps the 64 possible 6-bit values (0 through 63) to their designated character.
For example, encoding the word “Hello” works as follows. The ASCII codes for H, e, l, l, o are 72, 101, 108, 108, 111 in decimal — or 01001000, 01100101, 01101100, 01101100, 01101111 in binary. The encoding process groups these bits into 6-bit chunks, maps each chunk to its Base64 character, and produces the output string “SGVsbG8=” — where the = sign is a padding character indicating that the input length was not evenly divisible into complete three-byte groups.
Decoding reverses this process exactly — each Base64 character is looked up in the character table to retrieve its 6-bit value, the 6-bit values are concatenated to reconstruct the original binary data, and the binary data is interpreted as the original text, image, or file content.
How to Use the Base64 Encoder Decoder – Step by Step
Encoding Text to Base64
Click inside the input text area and type or paste the text you want to encode. Select the Encode option. Click the Encode button. Your Base64-encoded output appears instantly in the result area. Click Copy to copy the Base64 string to your clipboard for use in your code, API request, email, or any other application.
Decoding Base64 to Text
Click inside the input text area and paste your Base64-encoded string. Select the Decode option. Click the Decode button. The original decoded text appears in the result area. Click Copy to copy the decoded content. If the Base64 string contains encoding errors or is not valid Base64, the tool will indicate a decoding error rather than producing garbled output.
Clearing and Starting Again
Click the Clear button to empty the input and output areas and start a fresh encoding or decoding operation. There is no limit on how many encoding or decoding operations you can perform in a single session.
Common Uses of Base64 Encoding
Embedding Images in HTML and CSS
Web developers use Base64 to embed images directly into HTML and CSS files as data URIs rather than linking to external image files. A Base64-encoded image is included as a string in the format data:image/png;base64,[Base64string] directly in the src attribute of an img tag or as a CSS background-image value. This technique eliminates the HTTP request that would otherwise be needed to load an external image file, which can improve page load performance for small images like icons, logos, and UI elements that are always needed and change infrequently.
API Authentication and Tokens
Base64 encoding is widely used in API authentication systems. HTTP Basic Authentication encodes the username and password combination as a Base64 string that is sent in the Authorization header of every API request — in the format Basic [Base64(username:password)]. JWT (JSON Web Tokens) — the most widely used modern API authentication format — use Base64URL encoding for their header and payload sections. Understanding how to encode and decode Base64 is therefore an essential skill for developers working with REST APIs and authentication systems.
Email Attachments (MIME)
The MIME (Multipurpose Internet Mail Extensions) standard — which governs how email attachments are formatted and transmitted — uses Base64 encoding to convert binary attachment files into text-safe strings that can be included in email message bodies. When you attach a PDF, image, or any other file to an email, your email client Base64-encodes the file and includes the encoded string in the email’s MIME structure. The recipient’s email client Base64-decodes the attachment before presenting it for download or preview.
Storing Binary Data in JSON and XML
JSON and XML are text-based data formats that cannot directly represent arbitrary binary data. When applications need to include binary data — such as file content, image data, or cryptographic keys — within a JSON or XML structure, Base64 encoding provides the standard solution. The binary data is encoded as a Base64 string and stored as a JSON string value or XML text node, which can then be safely transmitted, parsed, and decoded by the receiving application.
Data URLs in Web Development
The data URL scheme (data:[mediatype];base64,[data]) allows any binary content to be embedded directly in a web page as a URL. This is used for images, fonts, audio files, and other binary resources that can be embedded directly in HTML, CSS, or JavaScript without requiring a separate HTTP request. Web performance optimization techniques sometimes use data URLs for critical above-the-fold images to eliminate render-blocking resource loads.
Storing Binary Data in Databases
Some database configurations or constraints make it easier to store text data than binary data. Base64 encoding allows binary content — such as small images, cryptographic keys, or serialized objects — to be stored as text strings in standard varchar or text database columns, avoiding the need for dedicated binary column types or separate file storage systems.
Cryptography and Security Applications
Cryptographic keys, digital certificates, and encrypted data are frequently represented in Base64 format for storage and transmission. PEM (Privacy Enhanced Mail) format — used to store SSL/TLS certificates, RSA private keys, and other cryptographic materials — is essentially Base64-encoded DER (Distinguished Encoding Rules) data wrapped in header and footer lines. When you open a .pem file and see a block of text between “BEGIN CERTIFICATE” and “END CERTIFICATE” markers, the content between those markers is Base64-encoded certificate data.
URL-Safe Data Transmission
Standard Base64 uses the characters + and / which have special meaning in URLs and can cause problems when Base64 data appears in query parameters or path segments. Base64URL — a variant of Base64 that replaces + with – and / with _ — is used specifically for URL-safe encoding of data that needs to appear in URLs. JWT tokens use Base64URL encoding for this reason. Our encoder supports standard Base64; for URL-safe encoding of JWT payloads, the + and / characters in the output should be replaced with – and _ respectively.
Base64 Encoding vs Encryption – An Important Distinction
A critical misconception about Base64 is that it provides security or privacy for data. Base64 is encoding, not encryption. The two are fundamentally different concepts with completely different security implications.
Base64 Encoding
Base64 encoding is a reversible transformation that converts data between formats with no secret key, no mathematical complexity designed to resist reversal, and no security properties. Anyone who encounters a Base64-encoded string can trivially decode it using any Base64 decoder — including the tool on this page — without any special knowledge, key, or password. Base64 provides zero confidentiality. Its purpose is data format compatibility, not data protection.
Encryption
Encryption is a cryptographic transformation designed to protect data confidentiality. Encrypted data can only be decrypted by someone who possesses the correct decryption key. Without the key, encrypted data should be computationally infeasible to recover — even with unlimited computing resources and full knowledge of the encryption algorithm. Encryption provides strong confidentiality guarantees that Base64 does not.
The practical implication of this distinction is important: never use Base64 to “protect” sensitive data like passwords, personal information, API keys, or confidential content. A Base64-encoded password is not a hidden password — it is a plainly readable password to anyone who decodes it. Use proper encryption (AES, RSA) or hashing (bcrypt, SHA-256) for any situation where actual data security is required.
Base64 Encoding vs Other Encoding Schemes
Base64 vs Hexadecimal (Hex)
Hexadecimal encoding represents binary data using 16 characters (0–9 and A–F), with each hex character representing 4 bits. This means one byte of binary data requires two hex characters — hex encoding increases data size by 100 percent compared to raw binary. Base64 encoding uses 64 characters, with each character representing 6 bits, meaning three bytes of binary data require four Base64 characters — a size increase of only 33 percent. Base64 is therefore significantly more space-efficient than hex for representing binary data as text, which is why it is preferred for transmitting binary content in text-based protocols.
Base64 vs URL Encoding (Percent Encoding)
URL encoding (also called percent encoding) converts characters that are not safe in URLs into a percent sign followed by two hex digits representing the character’s ASCII value. For example, a space becomes %20 and + becomes %2B. URL encoding is designed specifically for making arbitrary text safe for use in URLs — not for encoding binary data. Base64 is designed for converting binary data to text — not specifically for URLs (though Base64URL addresses this). The two serve complementary purposes and are often used together — Base64-encoded data embedded in a URL may need to be URL-encoded as well.
Base64 vs Base32
Base32 encoding uses a 32-character alphabet (A–Z and 2–7), with each character representing 5 bits. Base32-encoded data is approximately 60 percent larger than the original binary, compared to 33 percent for Base64. Base32 is less efficient but more human-friendly — the output only uses uppercase letters and a limited set of digits, making it easier to read, transcribe, and communicate verbally without ambiguity between similar-looking characters. Base32 is used in TOTP (Time-based One-Time Passwords) for two-factor authentication codes and in some file naming and content addressing systems.
Base64 in Different Programming Languages
JavaScript
JavaScript provides two built-in functions for Base64 operations: btoa() encodes a string to Base64, and atob() decodes a Base64 string. These work directly in the browser without any library imports. For Node.js, the Buffer class provides Base64 encoding and decoding: Buffer.from('Hello').toString('base64') encodes, and Buffer.from('SGVsbG8=', 'base64').toString() decodes.
Python
Python’s standard library includes the base64 module. base64.b64encode(b'Hello') encodes bytes to Base64, and base64.b64decode('SGVsbG8=') decodes Base64 back to bytes. Python also supports Base64URL encoding with base64.urlsafe_b64encode() and base64.urlsafe_b64decode().
PHP
PHP provides base64_encode() and base64_decode() functions as part of the core language without any imports required. These functions are commonly used for encoding email attachments, storing binary data, and handling API authentication in PHP web applications.
Java
Java’s java.util.Base64 class (introduced in Java 8) provides static factory methods for Base64 encoders and decoders. Base64.getEncoder().encodeToString(bytes) encodes, and Base64.getDecoder().decode(base64String) decodes. Java also supports URL-safe and MIME variants through Base64.getUrlEncoder() and Base64.getMimeEncoder().
Command Line (Linux/macOS)
The base64 command is available on most Linux distributions and macOS. echo -n 'Hello' | base64 encodes a string, and echo 'SGVsbG8=' | base64 --decode decodes it. This command-line access makes Base64 encoding useful in shell scripts, CI/CD pipelines, and server administration tasks.
Troubleshooting Common Base64 Issues
Invalid Base64 String Error
If decoding produces an error rather than output, the most common causes are: the input contains characters that are not in the Base64 alphabet (such as spaces, line breaks, or non-Base64 punctuation), the input length is not a multiple of 4 characters (Base64 strings must be padded to multiples of 4 with = characters), or the input was encoded with Base64URL encoding (which uses – and _ instead of + and /) and the decoder expects standard Base64. Try removing any whitespace from the input and checking for URL-safe character variants.
Garbled Output After Decoding
If decoding produces garbled or unreadable output rather than an error, the Base64 string may have decoded correctly but the output is binary data (such as image data or file content) rather than text. Attempting to display binary data as text produces garbled characters because the binary values do not correspond to printable text characters. Our tool is designed for text encoding and decoding — for decoding Base64-encoded binary files, a specialized tool or programming environment is more appropriate.
Padding Issues
Base64 strings must be padded with = characters to ensure their length is a multiple of four. Some Base64 implementations strip padding, particularly in URL contexts where = has special meaning. If you receive a Base64 string without padding, add one or two = characters to the end until the total length is a multiple of four, then try decoding again.
Line Break Issues
MIME Base64 (used for email attachments) traditionally inserts a line break every 76 characters. Some decoders handle these line breaks automatically, while others require the line breaks to be removed before decoding. If you are decoding MIME Base64 content and getting errors, try removing all whitespace and line breaks from the input before decoding.