Unwrap Nested Base64 – Free

Paste a value that was Base64 encoded two or more times. This nested Base64 decoder keeps decoding until the result is no longer Base64 text, then shows the layer count and the final text.

How to use the Unwrap nested Base64 tool

  1. Paste the value into the Nested Base64 box, or select Example to load a string that was encoded twice.
  2. Select Unwrap to start peeling the layers.
  3. Read the first line of the Result box, Decoded layers, to see how many times the value was decoded.
  4. Read the final text below the blank line. Copy takes the whole Result box, including the layer line.

How the nested Base64 decoder peels layers

The first decode is mandatory: the input must be valid Base64 or Base64URL and its bytes must be valid UTF-8 text. That counts as layer one. The tool then tries to decode the text it just produced. If that works and yields UTF-8 again, the new text replaces the old and the counter goes up. The first attempt that fails ends the loop, and the last good text is the answer.

Each pass uses the same tolerant reader as the other decoders on this site, so a layer may be wrapped across lines, unpadded, URL-safe or even a data URL.

A worked example

The sample was encoded twice. After two passes the text is Hello, which is five characters long. No Base64 string can have a length that leaves one character over after groups of four, so the third attempt fails and the loop stops.

Nesting is expensive. Every layer multiplies the length by four thirds: five characters become 8, then 12, then 16. Five layers make a value more than four times its original size.

U0dWc2JHOD0=   input
SGVsbG8=       after layer 1
Hello          after layer 2

Result:
Decoded layers: 2

Hello

Limits and edge cases

The stopping rule is simple, and that has consequences you should know about.

  • The loop ends after 20 layers. If the output still looks encoded, paste it back in and run the tool again.
  • If the first decode gives binary data, the tool reports the browser's UTF-8 decoding error and shows nothing.
  • If a deeper layer is binary, such as an image that was encoded twice, the tool stops one level above it and shows that level's Base64. Take it to the Base64 reader.
  • Text that is itself valid Base64 for UTF-8 bytes is decoded one step too far. A final value of QUJD comes out as ABC.
  • Only Base64 is peeled. A layer of percent-encoding, gzip or JSON quoting between two Base64 layers stops the loop.

Why data ends up encoded twice

Double encoding is almost always an accident at a boundary between two tools. A value is encoded by hand and then placed in a Kubernetes Secret data field, which expects Base64 and gets Base64 of Base64. A client encodes an attachment before passing it to an SDK that encodes it again. A message broker wraps a payload that was already wrapped by the producer.

Deliberate nesting shows up in obfuscated scripts and capture-the-flag puzzles. In production the right fix is at the source: find the extra encode call and remove it.

Frequently asked questions

How do I know if a string is double Base64 encoded?

Decode it once. If the output is another run of letters and digits, possibly ending in =, and that output decodes to something readable, the value was nested. This tool does the repeated decoding and counts the layers.

How many layers can it unwrap?

Up to 20 in a single run. Deeper nesting is handled by copying the remaining Base64 from the result back into the input and selecting Unwrap again.

Why did it stop while the output still looks like Base64?

Either the 20-layer limit was reached, or the next layer down is binary data and cannot be shown as text. In the second case, decode the displayed value with the Base64 reader to identify and download it.

Why was my text decoded one step too far?

The final text happened to be valid Base64 that decodes to valid UTF-8, so the tool could not distinguish it from another layer. This can happen with short identifiers made of letters and digits. Decode manually, one layer at a time, with Base64 to Text.

Does it handle URL-safe layers?

Yes. Every layer is checked separately, and a layer that contains a hyphen or underscore is decoded with the URL-safe alphabet. Standard and URL-safe layers can alternate within one value.

Related tools