Base64 Decode

Base64 decoder: paste a Base64 string and read the text or save the file. It accepts standard and URL-safe alphabets, missing padding, line breaks and data URIs, names any invalid character with its position, and runs in your browser.

Base64 to text
Accepts standard and URL-safe alphabets, missing padding, line breaks and data: URIs
13 bytes · no alphabet marks
The result updates as you type · text and files stay in this browser

How to decode Base64: four characters back to three bytes

Base64 writes bytes using 64 printable characters, six bits of data per character. Decoding reverses the encoding: look up each character's value in the alphabet (A is 0, Z is 25, a is 26, z is 51, 0 is 52, 9 is 61, + is 62 and / is 63), write each value as six bits, join all the bits, and cut them into groups of eight. Every four characters give 24 bits and therefore three bytes.

The four characters SGV4 show it. S is 18, G is 6, V is 21 and 4 is 56. As six-bit groups those are 010010, 000110, 010101, 111000, which join into 24 bits and cut again into the bytes 48 65 78. Those three bytes are the characters Hex.

Four Base64 characters back to three bytesHex is the bytes 48 65 78, which are the 24 bits 010010000110010101111000. Split into four groups of six bits they are 18, 6, 21, 56, and the characters at those positions in the Base64 alphabet are SGV4.SGV4characters, then their 6-bit values01001000011001010111100024 bits cut into bytes01001000011001010111100048 H65 e78 x
Decoding SGV4: each character is looked up for its 6-bit value, the four values are joined into 24 bits, and the bits are cut into the bytes 48 65 78 (Hex).
Decoding SGV4, character by character
PositionCharacterAlphabet valueSix bits
1S18010010
2G6000110
3V21010101
4456111000

The full alphabet table, with the padding rules and the standard it comes from, is on the Base64 reference page. The tool above does the lookup for you and decides, from what it finds, whether the result is text or binary data.

Padding and string length

Base64 text is always a multiple of four characters, because it is produced in groups of three bytes. When the data length is not a multiple of three, the last group is short and the encoder fills the output with = signs. One = means the last group held two bytes and two = means it held one. A decoder uses that to know how many bytes to keep from the last group.

Padding is redundant, since the length of the text already tells the decoder the same thing. Many producers drop it, and decoders that follow the rules strictly then fail with an error about padding. The table shows what each remainder of the length means, and this decoder treats every valid case without complaint.

What the length of a Base64 string means (after removing any = signs)
Length mod 4Final groupBytes it givesPadding that was removed
0four characters3none
2two characters1==
3three characters2=
1one characterinvalidno byte count fits

A remainder of 1 cannot happen in a correctly encoded string: one character carries only six bits, which is not enough for a byte. If that is what you have, a character was lost somewhere in the string, most often by a copy that cut the end off.

URL-safe Base64 and strings without padding

The standard alphabet contains + and /, and both have special meaning in URLs and file names. RFC 4648 defines a second alphabet for these places that uses - in place of + and _ in place of /, and the rest is identical. JSON Web Tokens use it without padding, and so do many URL parameters and cookie values.

The decoder accepts both alphabets and tells you which one it saw, so you do not have to switch a setting. A string that contains both +/ and -_ is reported as a mixed alphabet, which is almost always a sign of two strings pasted together or of a hand-edit. An example is the two bytes FB FF, which are written +/8= in the standard alphabet and -_8 in the URL-safe form without padding; the decoded bytes are the same. To write URL-safe output, use the Base64 encoder with that alphabet.

Base64 decoding errors and what causes them

Most failures come from the text around the Base64 and not from the encoding itself. The table lists the symptoms in the order they tend to appear, with the usual cause and what to do.

Why a Base64 string will not decode
SymptomLikely causeFix
Invalid character at position 1 or at the endQuotes, a trailing comma or a field name copied with the valueCopy only the characters between the quotes
Invalid character in the middleA space or line break inside the stringSpaces and line breaks are ignored by this decoder, but check for a cut-and-paste mistake
Spaces where + should beA URL or form decoder turned + into a spaceReplace the spaces with +
- or _ rejected by another toolURL-safe Base64 given to a standard decoderUse a URL-safe decoder or swap - to + and _ to /
Padding errorUnpadded input given to a strict decoderAdd = signs until the length is a multiple of 4
Length leaves remainder 1A character was lost, usually at the endGet the full string again
Output is the same Base64 againThe data was encoded twiceDecode the result once more
Output is binary noiseThe data is a file, compressed or encryptedSee the next section

Escaped slashes are a frequent problem in JSON. A Base64 string embedded in JSON may show \/ for every slash, because JSON allows that escape, and a decoder that gets the backslash sees an invalid character. Remove the backslash, or parse the JSON first so the string is unescaped.

When the decoded data is not text

Base64 carries any bytes, and text is only one possibility. If the result has bytes that are not valid UTF-8 text, the text output stays empty and the tool says why. If the first bytes match a known file type, it names the type and offers the file for download with the right extension. The signature of the file is visible in the Base64 itself: a string that starts with iVBOR is a PNG image, /9j/ is a JPEG, JVBERi is a PDF and UEsD is a ZIP archive or an Office document.

Open the matching tool for those cases: Base64 to image previews a decoded picture, and Base64 to PDF checks the PDF structure and shows the pages. For hashes, keys and other binary values, the useful view is hex, which Base64 to hex gives with separators and letter case of your choice.

Decoding Base64 inside a JWT or a data URI

A JSON Web Token has three parts separated by dots: a header, a payload and a signature, each written in URL-safe Base64 without padding. Pasting a single part decodes it. The header eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 decodes to {"alg":"HS256","typ":"JWT"}. The signature part decodes to raw bytes and is not text. Decoding a token shows what it claims; it does not prove the claims are true, because only checking the signature with the key does that.

A data URI begins with data:, a media type and the flag ;base64 before the encoded bytes, as in data:text/plain;base64,SGVsbG8=. The decoder detects the prefix, ignores it and decodes what follows the comma. The syntax is defined in RFC 2397 and is covered with images on the Base64 to image page.

Line-wrapped Base64: MIME and PEM

Long Base64 is wrapped onto lines because the formats that carry it were designed for text with a line limit. Email follows RFC 2045, which sets the maximum at 76 characters per line, ending in a carriage return and line feed. PEM files, which hold certificates and keys, use 64 characters between BEGIN and END lines, as set out in RFC 7468. Line breaks are not part of the data, and a decoder must skip them.

This decoder ignores whitespace anywhere in the input, so a block copied from an email source or a certificate file works as it is. For a PEM file, copy the lines between the BEGIN and END markers and leave the markers out; they contain characters that are not Base64. What you get from a certificate is DER bytes, which is binary and best read as hex.

Base64 decode in JavaScript, Python, Java, PHP and the shell

JavaScript
// Node.js
Buffer.from("SGVsbG8h", "base64").toString("utf8")        // 'Hello!'
Buffer.from("PDw_Pz4-Pg", "base64url").toString("utf8")   // URL-safe, no padding

// Browser: atob returns one character per byte, so decode UTF-8 explicitly
new TextDecoder().decode(Uint8Array.from(atob("4oKs"), c => c.charCodeAt(0)))   // '€'

Calling atob alone returns the bytes as Latin-1 characters, which is why decoded text with accents appears garbled in the browser console. Wrapping the result in a TextDecoder, as above, gives the UTF-8 text.

Python
import base64
base64.b64decode("SGVsbG8h")                       # b'Hello!'
base64.b64decode("SGVsbG8h", validate=True)        # raises binascii.Error on stray characters
base64.urlsafe_b64decode("PDw_Pz4-Pg==")           # padding required

base64.decodestring, which many older answers use, was removed in Python 3.9; use b64decode or decodebytes.

Java, PHP and C#
byte[] data = java.util.Base64.getDecoder().decode("SGVsbG8h");        // getUrlDecoder() and getMimeDecoder() also exist
$data = base64_decode("SGVsbG8h", true);                                  // true = strict, returns false on invalid input
byte[] data = System.Convert.FromBase64String("SGVsbG8h");
Command line and PowerShell
echo SGVsbG8h | base64 -d                                       # Hello!  (Linux, Git Bash; older macOS uses -D)
echo SGVsbG8h | openssl base64 -d

[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("SGVsbG8h"))

Decoding by hand: SGVsbG8= step by step

The string SGVsbG8= is eight characters, so it has two groups of four, and the final = tells you the last group is short. The first group, SGVs, has the alphabet values 18, 6, 21 and 44, which in six bits are 010010, 000110, 010101 and 101100. Joined, that is 010010000110010101101100, which cuts into the bytes 01001000, 01100101 and 01101100, or 48, 65 and 6C: the letters H, e and l.

The second group, bG8=, has only three alphabet characters before the pad. b is 27, G is 6 and 8 is 60, giving 011011, 000110 and 111100. Eighteen bits are not a whole number of bytes: the first sixteen, 01101100 and 01101111, are the bytes 6C and 6F (l and o), and the last two bits, 00, are padding bits that carry no data and are dropped. The whole string is the five bytes 48 65 6C 6C 6F, which is Hello. The count follows from the length: 8 characters × 3 ÷ 4 = 6 bytes, minus one for the single =, gives 5.

After Base64: reading the bytes as text in the right encoding

Base64 gives back bytes. Turning them into text needs a character encoding, and the tool uses UTF-8, which matches nearly all modern data. When the original text used another encoding, the Base64 decodes without error but the characters come out wrong. The same euro sign, for instance, has a different Base64 in each encoding, and the same string decoded in the wrong one gives different text.

Three Base64 strings for the euro sign and what they decode to
Base64BytesUTF-8Windows-1252UTF-16 LE
4oKsE2 82 AC€â‚¬invalid
gA==80invalid€invalid
rCA=AC 20invalid¬ €

The diagonal is the point: each string is the euro sign in exactly one encoding, and in the other columns it is invalid or a different character. If a decoded string shows a letter with a stray accent in front of it, or boxes, the usual fix is to run the bytes through the hex decoder with another encoding, which lets you choose among UTF-8, UTF-16, Latin-1 and Windows-1252.

Where you meet Base64 that needs decoding

An HTTP Basic authentication header is the most common sight: Authorization: Basic dXNlcjpwYXNz decodes to user:pass, a user name and a password separated by a colon. Kubernetes secrets store every value in Base64 under the data key, so reading one means decoding it, and a command such as kubectl get secret name -o jsonpath='{.data.password}' | base64 -d does it on the command line. Docker and cloud credential files use the same convention.

Email headers use Base64 for non-ASCII text in the encoded-word syntax defined in RFC 2047: =?UTF-8?B?SGVsbG8=?= is a subject line containing Hello, where B says Base64. SAML responses sent by HTTP POST are Base64 text of an XML document; the redirect binding compresses the XML with deflate first, so decoding it gives binary. Cookies, session tokens and query parameters often hold Base64 too. In each case the decoded result tells you what the application stores, and that is more than many people expect.

Strict and lenient decoders

Libraries disagree on what they accept, which is why a string can decode in one place and fail in another. Python's b64decode silently discards characters outside the alphabet unless you pass validate=True, while Java's basic decoder throws on any character it does not know, whitespace included, and its MIME decoder ignores them. PHP returns the decoded bytes for input with invalid characters unless the second argument is true, in which case it returns false. Go rejects bad characters but skips line breaks.

This decoder is lenient about what is harmless (whitespace, missing padding, either alphabet) and reports everything else. It never discards a character without telling you, because silent discarding turns a damaged string into plausible but wrong output. If you write a decoder of your own, decide the policy deliberately: strict checking suits security-sensitive input, and lenient reading suits data you want to recover.

Checking a decoded result

The number of decoded bytes follows from the length: the string length times three divided by four, minus the number of = signs. For SGVsbG8h, 8 characters give 6 bytes. If the tool reports a different count than you expect, for example one that is 33 percent larger than the file you started with, the string was probably encoded twice. A good check on anything important is to encode the result again with the Base64 encoder and compare it with the original string, remembering that the padding and the alphabet may differ.

A checklist for a string that will not decode

  1. Look at the first and last characters. Quotes, brackets, a trailing comma or a field name mean the string was copied with its surroundings.
  2. Check for a prefix. data:image/png;base64, or similar is handled, but a prefix such as base64: or Basic is not part of the data.
  3. Look for + signs that became spaces, and for %2B or %2F, which are escaped + and / from a URL. Unescape the percent sequences first.
  4. Look for - and _. They are the URL-safe alphabet and are accepted here, but a strict decoder elsewhere will refuse them.
  5. Compare the length with what you expect. A remainder of 1 after dividing by 4 means a character is missing.
  6. Check whether the decoded bytes are Base64 again, or a known file type. A result that starts with eyJ is JSON in Base64, and one that starts with H4sI is gzip data in Base64.
  7. If the text looks wrong and not damaged, try another character encoding on the bytes with the hex decoder.

The prefixes in step 6 are worth remembering. eyJ is the start of a JSON object, since a brace, a quotation mark and the first letter of a key encode to eyJ, and it is how a JWT part or an encoded configuration object announces itself. H4sI is the start of a gzip stream (1F 8B 08), common in compressed payloads that are then Base64 encoded for transport.

Decoding without any tool: the browser console

A one-line decode is available in every browser. Open the developer console and run atob("SGVsbG8h") to get Hello!. For text with accents or other non-ASCII characters, add the UTF-8 step shown above, new TextDecoder().decode(Uint8Array.from(atob(s), c => c.charCodeAt(0))), because atob alone gives one character per byte. In a terminal, base64 -d does the same job. The page tool exists for the cases where the one-liner is not enough: strings with URL-safe characters, missing padding, wrapped lines, a data URI prefix, or binary results that need a file type.

Base64 decoding is not decryption

Searches for base64 decrypt or Base64 decryption are common, and the answer is that nothing is encrypted. Base64 changes the form of data and has no key, so anyone can reverse it. If a string decodes to readable text, the text was only hidden from casual view; if it decodes to noise, the bytes may be encrypted or compressed data that was then encoded in Base64 for transport. Decrypting those needs the key and algorithm, which Base64 does not supply.

The practical rule is that Base64 never protects anything. Credentials, tokens and personal data written in Base64, for example in HTTP Basic authentication headers, are readable by anyone who sees the string. When a string seems to be in some other encoding, the auto decoder checks several at once.

Questions about decoding Base64

Why does my Base64 string fail with an invalid character error?

The string contains a character outside the Base64 alphabet. The usual causes are a space or line break inside the string, surrounding quotes copied along with it, a - or _ from the URL-safe alphabet read by a standard decoder, or a + that a URL turned into a space. The decoder names the character and its position.

What does incorrect padding mean?

The length of the string, once the = signs are counted, is not a multiple of four. Either the end of the string was cut off or the padding was removed. This decoder adds the missing = signs itself and tells you it did, so it decodes the usual unpadded strings, but a string whose length leaves a remainder of 1 is not valid at all.

Why is the decoded text full of strange characters?

Either the original data was not UTF-8 text or it was text in another encoding. A PNG, PDF or ZIP file decodes to bytes that look like noise as text, and the tool says what the first bytes match. Text in Latin-1 or UTF-16 decodes without a Base64 error but shows wrong characters as UTF-8.

Can I decode Base64 without the = at the end?

Yes. The = signs only fill the last group to four characters and carry no data. JWTs and many URLs drop them, and the decoder restores them. Only a length that leaves a remainder of 1 after dividing by 4 cannot be decoded.

Is my Base64 string uploaded when I decode it?

No. Decoding is done by JavaScript in your browser. The text you paste is not part of any request, and the tool works with the network disconnected once the page has loaded.