GizmoBench guides
Base64 Decode Guide: How to Decode Text, Images and Files

To decode Base64, you turn each character back into its 6-bit value, join those bits into one stream, and regroup them into 8-bit bytes. For anything longer than a few characters, a decoder does this in one step: paste the string into our Base64 decoder, and the original text, image or file comes back. The tool runs locally in your browser, with no upload and no account, so the string you decode stays on your device.
This guide covers what the decoding does, how to do it by hand once (which makes every error message easier to read), how to decode text, images and files, and what to check when a string will not decode. It also covers a point that surprises many people: decoding is not breaking encryption, because Base64 was never a lock.
TL;DR
- Base64 decoding maps each character to a 6-bit value, concatenates the bits, and reads them back as 8-bit bytes. Padding with
=tells the decoder how many bits to discard. - For quick work, use the browser-based Base64 decoder. It handles text, images and downloadable files, and processing happens locally.
- Most failures come from three things: stray characters (spaces, line breaks, quotes), missing or wrong padding, and the URL-safe variant, which uses
-and_instead of+and/. - Garbled output after a successful decode usually means the original was not text, or was text in a different character encoding.
- Base64 is an encoding, not encryption. Anyone can decode it, so it protects nothing.
Table of Contents
- What Base64 decoding actually does
- Decode a Base64 string by hand
- How padding works
- Decode Base64 text online
- Decode an image or a file from Base64
- Decoding in code
- When a Base64 string will not decode
- Decoding is not decrypting
- Common things people decode
- Where our decoder fits
- FAQ
- Sources
What Base64 decoding actually does
Computers store files as bytes, and a byte is 8 bits. Many text-based systems (email bodies, JSON, HTML, URLs) cannot carry arbitrary bytes safely, so Base64 re-expresses bytes using only 64 printable characters: A-Z, a-z, 0-9, + and /. Decoding is the exact reverse: each character is converted back to its 6-bit binary value and the bits are recombined to rebuild the original data.
The arithmetic explains the size change. RFC 4648, the standard that defines the format, describes it as mapping each 24-bit group (three input bytes) onto four 6-bit groups, each shown as one character. Three bytes become four characters, so encoded data is roughly one third larger than the original. Decoding shrinks it back.

A decoder does not need a key, a password or any context. The alphabet is public and fixed, which is why decoding is deterministic: the same string always yields the same bytes.
Decode a Base64 string by hand
Doing it once manually is the fastest way to understand padding and error messages. We will decode aGk=, an example bunny.net’s academy also walks through.
- Split the string into characters.
a,G,k,=. - Look up each character’s index in the alphabet.
A-Zare 0 to 25,a-zare 26 to 51,0-9are 52 to 61,+is 62 and/is 63. Soais 26,Gis 6 andkis 36. - Write each index as 6 bits. 26 is
011010, 6 is000110, 36 is100100. - Ignore the
=. It carries no data, only a signal about length. - Join the bits.
011010 000110 100100becomes011010000110100100, which is 18 bits. - Regroup into 8-bit bytes. The first 16 bits are
01101000and01101001. The last 2 bits (00) are leftover and discarded. - Convert the bytes.
01101000is 104, the ASCII letterh.01101001is 105, the letteri. The result ishi.
The discarded bits are where padding comes from, as the next section explains.
How padding works
Base64 works on groups of three bytes, but real data rarely divides evenly. The encoder pads the last group with = so that the output length is always a multiple of four characters.
The RFC 4648 test vectors show the pattern clearly (section 10 of the standard):
| Base64 | Decoded text | Bytes | Padding |
|---|---|---|---|
Zm9v |
foo | 3 | none |
Zm9vYg== |
foob | 4 | two = |
Zm9vYmE= |
fooba | 5 | one = |
Zm9vYmFy |
foobar | 6 | none |
MDN’s glossary explains that the last chunk may hold 2, 3 or 4 characters encoding 1, 2 or 3 bytes. A final group of four with one = yields two bytes, and with two == it yields one byte. This is useful as a quick sanity check: if a string’s length is not a multiple of four and has no padding, either the padding was stripped on purpose (common in URL-safe Base64) or part of the string is missing.
The standard also says that, in the general case, implementations must include the padding characters unless the specification that refers to Base64 says otherwise. That exception is why you meet padless strings in the wild, and why different decoders disagree about them.
Decode Base64 text online
For everyday decoding, a browser tool is the quickest route. The steps are the same on any page that does this job:
- Copy the Base64 string from its source. Take only the encoded part: if it sits inside quotes, a JSON field or a longer line such as
data:image/png;base64,..., copy only what comes after the comma or between the quotes. - Open the Base64 decoder and paste the string into the input.
- Read the output. If it is readable text, you are done. If it looks like random symbols, the data is probably binary (an image, a compressed file, a certificate) rather than text.
- Copy the result or, for binary content, download it.
Because our decoder runs in your browser and does not send the string to a server, it suits strings you would rather not paste into a stranger’s website: tokens, configuration values, snippets from internal systems. That is a design choice of the tool, and it is the reason we built it that way. If you want one page for both directions, the combined Base64 encoder and decoder covers text, files and data URIs.
A worked example
Suppose a log line contains SGVsbG8sIFdvcmxkIQ==. The string is 20 characters long, a multiple of four, and ends in two =, so the final group carries one byte. Decoded, it reads Hello, World!. Thirteen bytes of text produce 20 characters of Base64, which fits the 3-to-4 ratio once padding is counted.
Decode an image or a file from Base64
Base64 often appears as a data URI, a way of embedding a file directly in a web page or stylesheet. It looks like this:
data:image/png;base64,iVBORw0KGgo...
The part before the comma names the file type (here, PNG). The part after it is the Base64 data. To get the image back, decode the data portion as binary and save it with the matching extension. Our Base64 decoder is listed for text, images and downloadable files, so the same page covers this case.
A few practical notes:
- Check the media type first.
image/png,image/jpegandapplication/pdftell you which extension to give the downloaded file. A wrong extension produces a file that will not open even though the decode was perfect. - Large strings are normal. A 1 MB image becomes about 1.33 MB of Base64, and the string can span thousands of lines in an email source or a JSON file. Decoding locally in the browser avoids uploading that volume to a server.
- File signatures help. Many files start with recognizable bytes. Base64 strings that begin
iVBORw0KGgoare typically PNG images, and ones that begin/9j/are typically JPEGs. Treat this as a hint, not proof.
If you want to go the other way, for example to embed a small image in a stylesheet, the Base64 encoder turns local file bytes into a string.
Decoding in code
Developers often need to decode inside a script. The functions exist in every mainstream language, and their strictness differs in ways that matter when input is messy.
Python. The base64 module’s b64decode function takes parameters that control validation. According to the Python 3.15.2 documentation, with padded=True the last group must be =-padded and a binascii.Error is raised on incorrect padding, validate=True makes non-alphabet characters raise an error, and canonical=True rejects non-zero padding bits. The lower-level binascii.a2b_base64 offers a strict mode that raises an error on invalid data.
JavaScript. Browsers have long offered atob() for decoding, which returns a binary string rather than UTF-8 text, a frequent source of garbled accented characters. A newer specification, the TC39 proposal for Base64 in ArrayBuffer and Uint8Array, defines explicit handling of the final chunk: loose (the default) treats the last chunk as padded but throws if exactly one extra character remains, strict requires the last chunk to be exactly four characters including = with zero overflow bits, and stop-before-partial stops before an incomplete chunk.
The common thread is that strict decoders reject sloppy input while lenient ones guess. Which you want depends on whether you are reading trusted data (lenient is convenient) or validating input from outside (strict is safer).

When a Base64 string will not decode
Most failures fall into a short list. Work through it in order.
1. Stray characters
The standard says that implementations must reject data containing characters outside the Base64 alphabet unless the referring specification says otherwise. Email-style (MIME) formats are one such exception: they may ignore characters like line breaks. Pasted strings often carry extras: leading or trailing spaces, quotation marks, a trailing comma copied from JSON, or the data:...;base64, prefix. Remove everything that is not part of the encoded data.
2. Wrong or missing padding
Count the characters. If the length is not a multiple of four and the string was stripped of its = signs, add padding back: one = if the length leaves a remainder of three, two == if it leaves a remainder of two. A remainder of one is never valid, since a single leftover character cannot represent a whole byte. The TC39 specification, for instance, throws in loose mode when exactly one extra character remains.
3. The URL-safe variant
Standard Base64 uses + and /, which have special meaning in URLs. MDN notes that the URL and filename-safe variant replaces them with - and _ and omits padding, and that it is needed when data goes into a path segment or query parameter. If your string contains - or _, it is almost certainly this variant. Decode it with a tool that supports it, or swap the characters back and restore padding. Our Base64URL encoder produces URL-safe, unpadded output, which is a handy way to see what the variant looks like. If the string came from a web address, you may also need to undo percent-encoding first with the URL decoder.
4. Non-zero padding bits
Some strings decode but are not “canonical”. MDN gives the example of VR== versus VQ==: encoders set the extra trailing bits to zero, and decoders may optionally throw an error if they are not. Both strings can give the same byte in a lenient decoder. If you are comparing strings for equality, normalize them first.
5. The decode works but the output is garbled
This is not a Base64 problem. Base64 returns bytes, and what those bytes mean depends on the content. Three typical causes:
- The data is binary (an image, an archive, an encrypted blob), so showing it as text produces symbols. Save it as a file instead.
- The text uses a different character encoding than the one the viewer assumes. UTF-8 is the usual default; legacy data may be Latin-1 or UTF-16.
- The data was encoded twice. If the output of your first decode still looks like Base64, decode it again.
Decoding is not decrypting
A string that looks scrambled is not necessarily protected. RFC 4648’s security section says that base encoding visually hides information such as passwords but provides no computational confidentiality and adds no entropy, and that it has caused security incidents when users unknowingly revealed credentials in base-encoded exchanges. In plain terms: if a password, API key or personal detail is Base64-encoded, it is exposed to anyone who sees the string.
Two habits follow from that:
- Do not use Base64 to hide secrets. If something must stay private, it needs real encryption or should not be stored in that place at all.
- Treat decoded content with the same care as the original. A decoded string may contain credentials or personal data. Decoding in a tool that keeps the data in your browser is a reasonable precaution, and you should still avoid sharing the result.
The RFC also advises that decoders should not break on invalid input, including embedded NUL characters, and warns that silently ignoring bad characters can create a covert channel or trigger bugs such as buffer overflows. For anyone writing code that handles untrusted input, that is an argument for strict validation.
Note also that Base64 is not compression. The encoded form is always larger than the original, as the bunny.net explainer above points out.
Common things people decode
Base64 turns up in more places than most users expect. A few familiar cases:
| Where you find it | What it usually holds | What to do |
|---|---|---|
| Email source (MIME) | Attachments and encoded body text | Decode the block as a file; line breaks are normal there |
| Data URI in HTML or CSS | An embedded image or font | Take the part after the comma, decode as a file |
| JSON Web Token (JWT) | Two Base64URL segments: header and payload | Use a JWT decoder to read them |
| Configuration or API field | Text, JSON or a small binary value | Decode, then format the result if it is JSON |
| Certificate or key file (PEM) | A DER-encoded structure between header lines | Use a certificate decoder |
JWTs deserve a special mention. Their segments are Base64URL, so a general decoder can read them after you swap characters and add padding, but a dedicated page saves the steps. As with any Base64, readable contents do not mean the token is trustworthy, and decoding does not verify a signature.
Where our decoder fits
GizmoBench is a collection of browser-based tools for everyday and technical tasks, and the Base64 decoder is one of them. It runs locally in your browser, so there is no upload step, and it needs no account or installation. That combination is what makes it practical for strings you would not want to paste into a server-side service: log excerpts, config values and files you are handling for work.
If you handle Base64 together with other developer tasks, such as tidying a decoded JSON payload, the developer tools page collects the Base64 tool and the JSON formatter in one place. Core tool functions are free to use without signing up.
FAQ
How do I decode Base64 without a tool?
Look up each character’s value in the Base64 alphabet, write it as 6 bits, join all the bits, and regroup them into 8-bit bytes, discarding any leftover bits at the end. The manual example above decodes aGk= to hi this way. It is fine for a few characters but impractical beyond that, so a decoder is the sensible choice for real data.
Why does my Base64 string end with one or two equals signs?
The = is padding. Base64 encodes three bytes at a time, and when the final group has only one or two bytes, the encoder adds == or = so the length stays a multiple of four. One = means the last group decoded to two bytes, and == means it decoded to one.
Is Base64 encryption?
No. RFC 4648 states that base encoding provides no computational confidentiality, so anyone can decode a Base64 string with the public alphabet. It exists to carry bytes through text-only channels, not to protect them.
Why do I get an error about invalid characters or incorrect padding?
The string probably contains characters outside the alphabet (spaces, quotes, a data URI prefix) or its padding was removed. Strip the extras, restore the = signs so the length is a multiple of four, and check whether the string is the URL-safe variant with - and _.
Can I decode an image from Base64?
Yes. Take the data after the comma in the data URI, decode it as binary, and save it with the extension that matches the media type, such as PNG for image/png. Our Base64 decoder is built for text, images and downloadable files.
Sources
- RFC 4648: The Base16, Base32, and Base64 Data Encodings (rfc-editor.org)
- RFC 4648 on the IETF datatracker
- RFC 4648 section 12 security considerations (2rfc.net)
- Base64 glossary entry, MDN Web Docs
- Python base64 module documentation
- Python binascii module documentation
- TC39 proposal: Base64 in ArrayBuffer and Uint8Array
- How to Encode and Decode HTML Base64 using JavaScript (freeCodeCamp)
- What is Base64 Encoding & Decoding? (bunny.net academy)