Fundamentals · 7 min read

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

Quick answer

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

WhereCommand or call
Browser, no codePaste into the decoder; it shows text, hex and the file type
Linux / macOSecho 'TWFu' | base64 --decode (guide)
Pythonbase64.b64decode("TWFu") (guide)
JavaScriptatob("TWFu"), or Buffer.from(s, "base64") in Node (guide)
PowerShell[Convert]::FromBase64String("TWFu") (guide)

Open this in the decoder →

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.

ValueCharValueCharValueCharValueChar
0A16Q32g48w
1B17R33h49x
2C18S34i50y
3D19T35j51z
4E20U36k520
5F21V37l531
6G22W38m542
7H23X39n553
8I24Y40o564
9J25Z41p575
10K26a42q586
11L27b43r597
12M28c44s608
13N29d45t619
14O30e46u62+
15P31f47v63/

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.

  1. Look up each character. T = 19, W = 22, F = 5, u = 46.
  2. Write each value as 6 bits. 19 = 010011, 22 = 010110, 5 = 000101, 46 = 101110.
  3. Join the bits. 010011010110000101101110 (24 bits).
  4. Cut into 8-bit bytes. 01001101 01100001 01101110.
  5. Read each byte. 77, 97, 110, which in ASCII are M, a, n. So TWFu is Man.

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.

Show the working

Try TWE=, TQ== or SGVsbG8=.

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:

Base64Characters usedBitsBytes keptResult
TWFu4243Man
TWE=318 (16 + 2 filler)2Ma
TQ==212 (8 + 4 filler)1M

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 (iVBORw0KGgo is a PNG, JVBERi0 a PDF, H4sI gzip).
  • 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

  • eyJ at the start is {", the start of a JSON object. Every JWT begins this way.
  • AAAA is three zero bytes. Long runs of A mean 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.

Frequently asked

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.

Keep going

Related guides and tools.