Practical guide to Base64 Encoder & Decoder
By RankHush Tools · Updated
What a Base64 encoder and decoder does
Base64 represents bytes using a limited set of printable characters. It is useful when a system needs to carry binary data through a text-based format, such as an email attachment, a data field, or an API message. A Base64 encoded string is a representation of data, rather than a translation into another language.
Three input bytes normally become four encoded characters, so encoding usually makes the data around one third larger before any padding. The = character may appear at the end as padding. Base64 is reversible and provides no secrecy: anybody who has the string can attempt to decode it.
Encode text or decode a Base64 string online
Choose Encode to generate a Base64 encoded string online. For example, Hello becomes SGVsbG8=. Switch to Decode and enter SGVsbG8= to recover Hello. The input and output panels let you compare the values before copying them into another application. Keep your original text when whitespace or line endings matter.
For Base64 decode, this tool removes whitespace and accepts the URL-safe - and _ characters as well as the standard alphabet. It restores missing padding where possible, then checks that the decoded bytes form valid UTF-8 text. A malformed input produces an error instead of a misleading result.
Base64 in JavaScript, Python, Java and Linux
A Base64 encoder and decoder in JavaScript must account for Unicode. Browser btoa works with byte-like strings, so this tool first uses TextEncoder to obtain UTF-8 bytes. Decoding uses TextDecoder to reconstruct readable text. This avoids treating non-ASCII characters as if they were single bytes.
For the same task in a script, Python provides base64.b64encode and base64.b64decode, Java provides java.util.Base64, and many Linux systems provide the base64 command. Check the encoding, line wrapping and URL-safe variant expected by the receiving application. These examples explain compatible workflows; the page does not run Python, Java or shell commands.
Text decoding, image data and privacy
Use this online decoder for a Base64 string that represents text. A Base64 image decoder needs to preserve binary image bytes, whereas this page expects UTF-8 output. Pasting an encoded PNG or JPEG may therefore fail or produce unsuitable text. A data URL prefix is also different from the encoded data itself.
The conversion code runs on your device. No account, browser extension or software download is needed. This page is not an installable offline application, and loading it initially requires an internet connection. Use sample data when exploring unfamiliar encoded content and review the decoded text before using it elsewhere.
Define the bytes before comparing encoded strings
Two systems agree on Base64 only when they agree on the bytes being represented. For ordinary text in this tool, those bytes come from UTF-8. If another application starts with a different character encoding, a byte order marker or different line endings, its Base64 result can differ even when the text appears similar on screen. Begin a debugging task by identifying the original data and its expected representation rather than assuming one encoder is wrong.
Write down the direction of the operation as well. Encoding takes text and produces a transport representation. Decoding takes a transport representation and attempts to recover text here. Applying Encode to a string that was already encoded creates another layer; it does not normalize the original layer. Knowing whether a field contains raw text, encoded text or an entire structured message prevents a great deal of confusion.
For a controlled comparison, use a short known input such as Hello with no trailing space or newline. Encode it, copy the result and decode it again. Only after that small round trip works should you introduce the larger sample that fails in your integration. That progression separates a basic compatibility issue from a difference hidden in a long document.
Read the alphabet as data rather than words
Standard Base64 output uses uppercase letters, lowercase letters, digits and two additional symbols. Letter case matters because uppercase and lowercase characters represent different values. Do not apply a text cleanup step that lowercases the string or changes characters according to a language's typography rules. The result may look like a random word, but its characters are a precise representation of bytes.
The equals sign can appear at the end as padding. It is not a password separator or a marker saying the result is encrypted. Padding describes the final partial group of bytes in the encoded representation. Copy the entire output as supplied unless the receiving protocol explicitly requires another form. Removing punctuation indiscriminately is not a safe way to prepare an encoded value for a form.
Formatting a Base64 value for display is different from changing its contents. A browser may wrap a long line visually without inserting real line breaks. Conversely, copying a block from an email may include actual whitespace. When exact transport bytes matter, inspect the underlying string or downloaded text rather than assuming that a visible line break proves a different encoded payload.
Understand padding with short round trips
Use three small inputs to see the effect of the final byte group. The text f encodes as Zg==, fo as Zm8= and foo as Zm9v. These examples have one, two and three ASCII bytes respectively. They show why a valid result can end with two padding characters, one padding character or none without implying that one result is more secure than another.
The decoder accepts supported missing padding by normalizing the final group, but not every arbitrary shortened value is recoverable. A fragment that has lost meaningful encoded characters is different from one that has only omitted the final padding. Check the source system's expected variant instead of appending random letters until an error disappears. A successful parse of a changed string does not prove that the original data was recovered.
When sending data to a strict receiving service, use the form specified by that service. A permissive decoder's acceptance rules are not a universal protocol contract. The normal Encode output from this page uses standard Base64. If another service requires an unpadded URL-safe representation, perform that documented transformation deliberately or use a library that exposes the exact variant as an option.
Work with Unicode text intentionally
Text can contain accented letters, non-Latin scripts, emoji and combining characters. UTF-8 represents many of those characters with more than one byte, so counting visible letters is not a reliable way to predict the encoded length. This tool converts the text into UTF-8 bytes before encoding and uses a UTF-8 decoder when recovering text. That is why it can handle more than plain ASCII examples.
Two visually identical strings can sometimes have different Unicode representations. For example, a character with an accent may be represented as a precomposed character or as a base letter followed by a combining mark. Base64 preserves the chosen bytes; it does not automatically decide that visually equivalent text should be normalized into one form. If your application requires normalization, define it before encoding and apply it consistently.
Emoji can also contain several code points even when they appear as one symbol. Avoid slicing an encoded result according to how many visible characters you think its source contained. Test the full round trip with a realistic multilingual sample, and compare the recovered text rather than merely checking whether it looks approximately right in a narrow input field.
Keep spaces and line endings when they are meaningful
Encoding Hello, Hello followed by a space, and Hello followed by a newline produces different results because the input bytes differ. This is expected. If two integrations disagree, check for leading spaces, an automatically appended final newline and line-ending conventions before investigating more complex causes. Copying from a document or terminal can add characters that are difficult to notice in the interface.
In Decode mode, this tool removes whitespace from the encoded input before interpreting it. That allows a wrapped Base64 block to be read as one continuous value. It does not mean the decoded text loses its own intentional spaces or newlines. Whitespace outside the encoded alphabet and whitespace represented inside the original payload play different roles.
Do not paste a list of independent Base64 records and assume they will be decoded line by line. This page treats the cleaned input as a single value rather than offering a per-line processing option. Decode records individually or use a script designed for a batch format. Keep boundaries explicit when a log or data export contains several separately encoded fields.
Recognize Base64URL in web protocols
The URL-safe variant replaces two symbols from standard Base64 with characters better suited to URLs and filenames. Many uses also omit padding. The decoder here accepts the supported URL-safe characters and restores padding as needed. The encoder, however, produces standard Base64; the page does not offer a separate URL-safe output switch. Check the exact representation required by the receiving protocol.
A JSON Web Token normally contains several Base64URL-encoded segments separated by periods. The whole token is not one ordinary Base64 string. Use the JWT Decoder when you want to inspect its JSON header and payload. That tool understands the three-part structure, while this page focuses on a single encoded text value. Pasting the entire dotted token into this decoder will not perform JWT verification.
Also distinguish URL encoding from Base64URL. A sequence containing percent escapes belongs to another transformation layer. You may need to undo a documented outer layer before decoding the payload, but guessing repeatedly can change the data. Follow the producer's format and inspect each step with harmless sample data so the order of transformations is clear.
Separate a data URL prefix from its payload
A data URL can combine a media type, a declaration about encoding and the encoded content. For example, a text data URL may begin with data:text/plain;base64, before the actual Base64 characters. That prefix describes how to interpret the value; it is not part of the encoded payload itself. This text decoder does not automatically parse every type of data URL wrapper.
If you know the payload represents UTF-8 text, separate the documented prefix and decode the remaining value. If it represents a PNG, JPEG, PDF or another binary file, use a binary-aware workflow that preserves the bytes and the intended file type. Turning arbitrary binary bytes into readable UTF-8 is a different task and can correctly result in an error here.
Do not treat successful extraction from a data URL as a guarantee that its contents are appropriate to open or execute. Review the media type and source and use a suitable application. This tool does not render arbitrary decoded HTML or run decoded scripts. It displays text for inspection, which lets you examine a value without treating its contents as instructions.
Use the tool in a JSON debugging workflow
An API may place an encoded value inside a JSON string. First parse or inspect the outer JSON to identify the exact field, then decode that field's value. Do not include the surrounding quotation marks, property name or commas. If the decoded text is itself JSON, use the JSON Formatter to inspect its structure after decoding. Keeping those layers separate makes errors easier to locate.
For example, a test field containing SGVsbG8= decodes to Hello. A different field could contain encoded JSON describing a small configuration. That does not make every JSON field a Base64 field: an API can also contain ordinary text, identifiers and other encodings. Use the API's documentation to decide which transformation applies rather than trying to decode every string that contains letters and numbers.
After editing decoded content, encode the intended new text and insert the complete output back into the correct JSON string. Check any additional protocol checksums or signatures separately. Changing a decoded payload can invalidate a signed request even if the new JSON and Base64 are individually well formed. A converter does not reissue an application's authorization or recompute unrelated integrity fields.
Recognize double encoding without guessing
Sometimes a pipeline encodes a value twice by mistake. Decoding once may then reveal another string that resembles Base64 instead of the expected message. That resemblance is a clue, not proof: ordinary text can also happen to contain characters from the alphabet. Compare the producer's documented pipeline and a known test input before deciding another decoding step is appropriate.
Record a small example at each boundary: the original text, the first encoded value and the actual field sent to the receiving system. A test that asserts the expected value at each stage helps locate the extra transformation. Fixing the producer is usually clearer than teaching every consumer to guess how many layers it received.
Do not add an automatic repeated-decoding loop to a production integration merely because it makes one sample look right. It can conceal malformed input and make the data contract unpredictable. This page performs the direction you choose on the value you supply. Keep the number and order of operations explicit, particularly when data passes through logs, queues and several independently maintained services.
Diagnose an invalid-character or length error
Check whether you copied a wrapper, a whole token, quotation marks or an error message along with the encoded field. The supported alphabet does not include arbitrary punctuation. An input whose meaningful length has an impossible final group cannot be repaired by adding only padding. Obtain the original value again when a copy appears truncated rather than altering it until it produces readable output.
If the alphabet and length look plausible but UTF-8 decoding fails, the underlying payload may be binary or text encoded using another character set. That failure is not proof that the Base64 itself is meaningless. It tells you that this text-oriented tool cannot interpret the decoded bytes as valid UTF-8. Return to the producer and determine the actual content type and encoding.
Try a known small sample in the same browser to establish that the interface is working. Then reduce the failing case in a controlled local workflow. When reporting a bug, include a harmless input that reproduces the error, the chosen direction and the browser. Do not publish a private encoded value on the assumption that nobody can read it.
Choose a binary or large-file workflow when needed
This page works with text entered into its interface and exports text. It does not provide an arbitrary file upload form, a binary image viewer or a streaming decoder for very large archives. Those tasks require different handling so bytes are preserved without forcing them through a text decoder or holding several large representations in memory at once.
Base64 increases the amount of data before any transport compression, and a browser can hold the input, byte arrays and output simultaneously during conversion. A very large pasted value can therefore make the page slow even if the device has enough space to save the final file. For bulk or production processing, use a maintained library or command-line tool appropriate to the data size and binary format.
For an image-format change, use the Image Converter rather than encoding a photograph as text and expecting it to become another image format. For reducing image bytes, use the Image Compressor. Base64 changes representation; it does not resize pixels, remove visual detail or optimize an image codec. Choosing the right operation avoids an unnecessary expansion of the file you wanted to make smaller.
Compare programming workflows carefully
In a browser application, TextEncoder provides UTF-8 bytes for text, while a Base64 operation turns those bytes into the encoded alphabet. A direct call to btoa with arbitrary Unicode text is not an equivalent replacement. When implementing the same operation in another language, choose the text encoding explicitly before passing bytes to its Base64 library, and decode recovered bytes with the matching character set.
Python and Java libraries distinguish bytes from strings, while shell tools commonly read byte streams from files or standard input. A command that appends a newline before encoding can differ from a browser input without that newline. A command that wraps output can differ in presentation while representing the same payload. State those choices in a test rather than comparing visually and declaring an implementation incompatible.
Use a set of round-trip tests containing plain ASCII, a deliberate newline and multilingual text. Compare known expected outputs for small cases and exact recovered text for larger ones. If an integration uses URL-safe output or omits padding, include that requirement in the test names and assertions. This makes the contract clearer to a future maintainer than a comment saying the string is simply encoded.
Distinguish reversible representation from protection
Anyone who receives an ordinary Base64 value can attempt the reverse operation. It does not provide password storage, encryption, digital signatures or proof of who created the data. A field labelled encoded should not be assumed confidential. Review how that field is logged, copied into tickets and exposed in a browser, especially if its decoded contents include credentials or personal details.
Base64 can be one layer inside a secure protocol without supplying the protocol's security itself. A signed token, an encrypted message and an ordinary encoded string have different properties. Use the documented cryptographic and authentication mechanisms of the system you are integrating with, then use this tool only to inspect an appropriate non-sensitive representation.
The same distinction matters when helping another person debug a problem. Redact the actual sensitive value before sharing it, rather than merely Base64-encoding it to make it less readable at first glance. Keep a representative dummy value with the same structure. That provides useful evidence without turning a support conversation into another place where the original secret is stored.
Keep a clean record of the result
Use Copy for a direct transfer and the text download when a project needs a saved result. Verify that the receiving field contains the current output, particularly after changing the input or switching the direction. A clipboard can contain an older value if a copy operation was blocked. When exact bytes matter, compare the saved text rather than retyping a long encoded string.
Keep the original alongside the encoded result during a debugging session, clearly naming which is which. This makes it possible to repeat the round trip and explain what changed. For production data, follow the project's retention and secret-handling practices rather than treating a browser download folder as a permanent secure archive. Clear temporary files and clipboard history on shared devices when the work is complete.
The conversion itself runs locally, while loading a website can still involve hosting and analytics services described in its privacy information. Use the built-in sample to learn the interface and a small controlled example to investigate a protocol. The most useful outcome is a clear understanding of the transformation your application expects, with a result you can verify and reproduce.
Distinguish empty data from a missing value
An empty string can legitimately encode to an empty representation, while a missing application field may mean something else entirely. This interface asks for input when you try to decode an empty field so that an accidental omission is visible. Do not replace a missing value with the literal text null or an arbitrary padded fragment unless the receiving data contract specifies that representation. In a test suite, cover an absent field, an explicit empty string and a non-empty encoded value separately. These cases can lead to different validation or fallback behavior even though they look similarly blank in a compact log. Clear distinctions make an integration easier to maintain than silently converting every empty-looking value into the same result.