How to decode Base64.
Most of the time you paste the string into a decoder or call one function. But knowing what the decoder does makes the errors make sense: why a string is “invalid”, what the = means, and why some output is gibberish. Here is the whole process, with a box that shows the working for any string you type.
Updated 9 November 2026
The fast way: paste the string into the decoder, or use base64 -d (Linux/macOS), base64.b64decode() (Python) or atob() (JavaScript). By hand: (1) look up each character's value 0–63 in the Base64 alphabet, (2) write each value as 6 bits, (3) join the bits, (4) cut them into 8-bit bytes, (5) read each byte, usually as an ASCII or UTF-8 character. Each = at the end means the last group was short, so you drop the leftover filler bits. TWFu decodes to Man.
The quick ways
| Where | Command or call |
|---|---|
| Browser, no code | Paste into the decoder; it shows text, hex and the file type |
| Linux / macOS | echo 'TWFu' | base64 --decode (guide) |
| Python | base64.b64decode("TWFu") (guide) |
| JavaScript | atob("TWFu"), or Buffer.from(s, "base64") in Node (guide) |
| PowerShell | [Convert]::FromBase64String("TWFu") (guide) |
The rest of this page is what all of those do internally.
What you need: the alphabet
Base64 has 64 symbols, each standing for a number from 0 to 63. This is the standard alphabet from RFC 4648 §4. Capitals come first, then lower case, then digits, then + and /. The URL-safe variant swaps the last two for - and _, with the same values.
| Value | Char | Value | Char | Value | Char | Value | Char |
|---|---|---|---|---|---|---|---|
| 0 | A | 16 | Q | 32 | g | 48 | w |
| 1 | B | 17 | R | 33 | h | 49 | x |
| 2 | C | 18 | S | 34 | i | 50 | y |
| 3 | D | 19 | T | 35 | j | 51 | z |
| 4 | E | 20 | U | 36 | k | 52 | 0 |
| 5 | F | 21 | V | 37 | l | 53 | 1 |
| 6 | G | 22 | W | 38 | m | 54 | 2 |
| 7 | H | 23 | X | 39 | n | 55 | 3 |
| 8 | I | 24 | Y | 40 | o | 56 | 4 |
| 9 | J | 25 | Z | 41 | p | 57 | 5 |
| 10 | K | 26 | a | 42 | q | 58 | 6 |
| 11 | L | 27 | b | 43 | r | 59 | 7 |
| 12 | M | 28 | c | 44 | s | 60 | 8 |
| 13 | N | 29 | d | 45 | t | 61 | 9 |
| 14 | O | 30 | e | 46 | u | 62 | + |
| 15 | P | 31 | f | 47 | v | 63 | / |
A shortcut that saves looking things up: A–Z are 0–25, so subtract 65 from the ASCII code; a–z are 26–51, subtract 71; 0–9 are 52–61, add 4.
Decoding by hand, step by step
We'll decode TWFu.
- Look up each character.
T= 19,W= 22,F= 5,u= 46. - Write each value as 6 bits. 19 =
010011, 22 =010110, 5 =000101, 46 =101110. - Join the bits.
010011010110000101101110(24 bits). - Cut into 8-bit bytes.
010011010110000101101110. - Read each byte. 77, 97, 110, which in ASCII are
M,a,n. SoTWFuisMan.
Every 4 Base64 characters carry 24 bits, which is exactly 3 bytes. That is the whole trick, and the reason Base64 output is about a third longer than the input.
What the = signs mean
If the original data wasn't a multiple of 3 bytes, the last group of characters is short. The encoder fills it with zero bits and adds = so the length stays a multiple of 4. When decoding, you drop the filler:
| Base64 | Characters used | Bits | Bytes kept | Result |
|---|---|---|---|---|
TWFu | 4 | 24 | 3 | Man |
TWE= | 3 | 18 (16 + 2 filler) | 2 | Ma |
TQ== | 2 | 12 (8 + 4 filler) | 1 | M |
So: two characters give one byte, three give two bytes, four give three. One leftover character can never happen, because 6 bits can't make a byte. If you see that, the string was cut off. The padding guide has a calculator and the length formula.
When the result looks like gibberish
The steps above always give you bytes. Whether those bytes are readable is a separate question:
- Accented letters come out as two odd characters (
éinstead ofé). The bytes are UTF-8 but were read one byte per character. Decode them as UTF-8. - Every other character is blank or a dot. The text is UTF-16, common in Windows and PowerShell data. Read the bytes as UTF-16LE.
- Nothing readable at all. It's binary: an image, a PDF, compressed or encrypted data. Check the first characters against the file-signature table (
iVBORw0KGgois a PNG,JVBERi0a PDF,H4sIgzip). - It contains
-or_and your decoder rejects it. It's URL-safe Base64: swap them for+and/, or use the Base64URL decoder.
Decoding in your head: three patterns worth knowing
eyJat the start is{", the start of a JSON object. Every JWT begins this way.AAAAis three zero bytes. Long runs ofAmean zeros, common in binary formats and UTF-16 text.==at the end means the data length divided by 3 left 1 byte over; a single=means it left 2.
Published 9 November 2026. Spot an error? Email contactus@base64decode.tools.
Common questions.
Look up each character's value (0 to 63) in the Base64 alphabet, write each value as 6 bits, join all the bits, cut them into 8-bit bytes, and read each byte. Drop any leftover filler bits at the end; the = signs tell you there are some.
TWFu decodes to Man. T, W, F and u are 19, 22, 5 and 46, which give the bits 010011 010110 000101 101110, regrouped as the bytes 77, 97 and 110.
The decoding worked but the bytes aren't plain ASCII text. They may be UTF-8 or UTF-16 text read with the wrong character set, or binary data such as an image, PDF or compressed file.
No. It must use only the 64 alphabet characters (plus = at the end), and its length without padding can't leave one character over after groups of 4. Strings with - and _ are URL-safe Base64 and need converting first.
No. Base64 has no key, so decoding is a fixed lookup anyone can do. If decoded data still looks random, it may be encrypted, and that needs the right key.