Nested Base64: Peeling Layers and Counting the Depth

Security Fundamentals Level 2/4 ~3 min September 11, 2026

The challenge

Someone wrapped a short message in base64 over and over again before dropping it in a paste bin, apparently under the impression that repetition adds security. It does not add any, but it does add depth. This time the message itself is not the prize, because the last layer just tells you that you have finished. What is being asked for is the depth: peel the input one base64 layer at a time and count how many times you had to decode before readable English appeared. Decoding once more than necessary will fail loudly, which is a useful way to confirm you stopped in the right place. Submit the number of base64 layers.

What you'll learn

  • Peel nested encoding layers one operation at a time
  • Recognise that an intermediate layer still looks like base64
  • Use a decode failure as a signal that you have gone one step too far
  • Understand that base64 expands rather than compresses data
  • Explain why repeated encoding adds no security

Skills tested

Encoding recognitionIterative decodingMalware and artifact triage

Prerequisites

  • Knowing what base64 looks like
  • Awareness that encoding is not encryption

How it works

Every other decoding exercise asks what the message says. This one asks how deep it was buried, which is a different skill and a surprisingly practical one. Analysts meet nested encoding constantly, in obfuscated droppers, in phishing attachments and in exfiltration payloads, and the reflex that matters is not stopping at the first successful decode.

The trap is that base64 output is itself valid base64 input. Decode one layer of a seven-layer wrap and you get another meaningless block of the same alphabet, which looks exactly like a failed decode of an encrypted blob. Analysts who stop there conclude the data is encrypted and move on. The correct habit is to keep decoding while the output still has the shape of the encoding, and to stop only when it stops.

Here that point arrives after seven taps, where the output reads as an English sentence. The eighth tap is the confirmation, and it is a loud one: the plaintext contains spaces and full stops, which are outside the base64 alphabet, so the decoder throws and the lab shows an error marker rather than silently returning something plausible. Seven decodes reach text and eight fails, so the depth is exactly 7.

Worth noticing on the way down: the string got longer at every layer, not shorter, because base64 encodes three bytes as four characters and grows the data by roughly a third each time. Seven layers of wrapping cost a great deal of size and provide no confidentiality at all, because anyone can reverse every one of them without a key. The other three buttons are decoys that apply cleanly to base64 text and return convincing garbage, which is the usual cause of a miscount.

Common mistakes

  • Counting characters or estimating from length. The count is the number of decode steps, which the stack shows directly.
  • Stopping early because the output still looks encoded. Every intermediate layer looks like base64. That is the whole trap.
  • Answering 8 after the failed tap. The eighth press errors and does not peel a layer, so it does not count.
  • Mixing in the decoy transforms. rot13, reverse and hex apply without complaint to base64 text and corrupt the chain, making the count unreliable. Use undo and reset if that happens.
  • Submitting the message text. The final sentence exists to tell you that you have finished; the answer is the number of layers.

How to defend against it

Nested encoding is an obfuscation and detection-evasion technique, not a protection, and both sides of that matter.

  • Never treat base64 as a security control. It is reversible by anyone, with no key, at any depth.
  • In detection tooling, decode recursively with a sane depth limit and scan the output at every level, since signatures matching only the outermost layer are trivially defeated by one more wrap.
  • Treat deep nesting as a signal in itself. Legitimate data is rarely encoded seven times, so depth is a useful feature for triage scoring.
  • Watch for the size tell: repeated encoding inflates payloads by about a third per layer, which makes heavily wrapped content stand out by volume.
  • When you genuinely need confidentiality, use authenticated encryption with a managed key, and keep encoding for what it is actually for, which is safe transport of bytes through text-only channels.

Full solution

Pro and Max members unlock the complete step-by-step walkthrough.

Go Pro

Community stats

185 completions
83% success rate
uika First blood

Related Daily Hacks

25,000+ Hackers 100+ Labs & Courses Free
Start Hacking Free