A search term leaves your code as hello world and arrives at the server as the literal text hello%20world, percent sign and all. Nothing matches, nothing errors, and the log line looks almost right. The usual culprit is double encoding: the value was percent-encoded, and then, somewhere along the way, encoded again.
This guide explains the mechanism, shows how to recognise a double-encoded value on sight, and gives the fix that actually holds up, using the free URL Encoder/Decoder on Ovatly to test each step instead of guessing.
Contents
- Quick answer
- How the second pass does its damage
- How to spot a double-encoded value
- How to fix it, step by step
- Worked example: a search phrase encoded twice
- Limitations and honest warnings
- Common mistakes
- FAQs
- Conclusion
Quick answer
A value is double-encoded when it passes through a percent-encoder twice. The first pass turns a space into %20; the second pass sees the % as an ordinary character that cannot travel raw, and encodes it as %25, producing %2520. A server that decodes once, which is the normal behaviour, recovers hello%20world instead of hello world. Spot it by looking for %25 followed by two hex digits, confirm by decoding once with the URL Encoder/Decoder and checking whether the output is still encoded, and fix it by encoding the raw value exactly once.
How the second pass does its damage
Percent-encoding has one rule that makes double encoding inevitable once a value is encoded twice: the % sign itself is not safe to carry raw, so an encoder must turn it into %25. That rule is correct and necessary. It is what lets a literal percent sign survive a trip through a URL as data.
The trouble is that an encoder cannot tell the difference between a % that a person typed and a % that a previous encoder put there. Feed 100% sure to an encoder and you get 100%25%20sure, correct. Feed the already-encoded 100%25%20sure to the same encoder and it does exactly the same job on what it sees: every % becomes %25, and the string comes out as 100%2525%2520sure. Each pass is honest. The composition is the bug.
In practice the second pass comes from layering. A value is encoded by a form handler, then the redirect builder that receives it encodes it again because it treats all incoming values as raw. Or a template encodes a variable that the router had already encoded. Neither layer is wrong about its own job; they are wrong about each other's. The result is a URL that survives transport perfectly and means something subtly different from what anyone intended.
How to spot a double-encoded value
The fingerprint is %25 doing suspicious work. One occurrence means little: a raw value containing a real percent sign encodes to %25 honestly. But a value studded with %2520, %2526, %253D and %252F is showing you the second pass directly. Each of those reads as "an encoded percent sign, followed by the two digits of the original encoding": %2520 is an encoded %20, which was an encoded space.
The confirmation test takes seconds. Decode the value once. If the output is clean readable text, the value was encoded once and your problem is elsewhere. If the output still contains %XX sequences that look like encoding, the value was encoded at least twice, and one decode only peeled off the outer layer. Decode that intermediate result and you should reach the raw text, which tells you exactly how many passes were stacked.
How to fix it, step by step
- Open the URL Encoder/Decoder.
- Paste the suspect value and press Decode once. If the result still looks encoded, the value was double-encoded.
- Go back to the source if you can: find the raw, unencoded value before any layer touched it.
- Encode that raw value exactly once, in Component mode if it is a single value going into a query string.
- If you cannot reach the raw value, decode the broken one repeatedly, checking after each pass, until you reach clean text, then encode that text once. Note that a stray
%or an incomplete sequence like%2at the end returns a clear error from the decoder, which usually means the string was also copied incompletely.
Then fix the cause, not just the instance: decide which single layer owns encoding for that value, and make every other layer pass it through untouched.
Worked example: a search phrase encoded twice
Start with the raw phrase hello world & more. One pass through Component mode gives the correct form:
hello%20world%20%26%20more
Now imagine that string is handed to a second component that assumes it is raw and encodes it again. Every % becomes %25:
hello%2520world%2520%2526%2520more
That is the broken URL. A server decoding once, as servers do, recovers hello%20world%20%26%20more and searches for that literal text, percent signs included. No match, no error, just an empty result set.
The repair follows the steps above. Decode the broken string once and you get back the singly encoded form, still full of %20 and %26, which confirms the diagnosis. Decode that and you reach hello world & more, the raw value. Encode the raw value once and you land on the correct string again, identical to the first pass. Three checks, no guessing, and the intermediate decode is the proof that two passes happened rather than one.
Limitations and honest warnings
Not every %25 is a crime scene. A whole URL placed inside another URL's query parameter is encoded once, as a component, and its existing %20 sequences legitimately become %2520 in the outer URL, because the outer layer will be decoded first and the inner URL must still be encoded when it is extracted. That looks identical to accidental double encoding, and only the context tells them apart: ask how many decodes the value will actually receive on its journey.
Repeated decoding is a diagnostic, not a repair strategy for production data. A raw value that genuinely contains the text %20 encodes to %2520 on its first, correct pass, and blindly decoding until no % remains will corrupt it. Always confirm against the known raw value when you have one.
And the standing warning for this whole family of tools: encoding is not encryption. A double-encoded secret is a readable secret twice over, and anyone can peel both layers with the same decoder you used to diagnose the problem.
Common mistakes
- Decoding until it "looks right" and shipping that. Without checking against the raw value, you cannot tell a repaired string from a corrupted one. Verify the round trip: raw, encode once, compare.
- Fixing the symptom in one URL and leaving the pipeline alone. If two layers both encode, tomorrow's values break the same way. Assign encoding to one layer.
- Assuming
%25always means double encoding. A literal percent sign in the raw value produces%25on a single correct pass. Context and the decode test decide. - Encoding defensively "just in case". Encoding a value because it might already be encoded is how the second pass happens. Pass values through untouched unless your layer owns the encoding.
- Mixing the
+convention into the diagnosis. In form-encoded query strings a space may appear as+; that is a separate convention, not a sign of double encoding. This tool uses%20for spaces, which is valid everywhere in a URL.
FAQs
What exactly is double encoding?
Encoding a string that was already percent-encoded. The second pass treats the % signs as data and encodes each one as %25, so %20 for a space becomes %2520.
How can I tell if a value is double-encoded?
Look for %25 followed by two hex digits, such as %2520 or %2526. Then decode once: if the result still contains %XX sequences, the value went through the encoder twice.
How do I fix a double-encoded URL? Decode once to get back to the singly encoded form, and check it decodes cleanly to the raw text. Better still, return to the original raw value and encode it exactly once.
Why does double encoding happen so often? Because values pass through layers: a form handler, a redirect builder, a template, a router. If two layers each encode the same value because neither knows the other did, the encoding stacks.
Is a %25 in a URL always a mistake?
No. A raw value that genuinely contains a percent sign encodes to %25 on the first pass, correctly. And a whole encoded URL placed inside another URL's parameter is encoded once as a component, which makes its % signs %25 by design.
Conclusion
Double encoding is a bookkeeping failure, not a mystery: one value, two encoders, and a % that becomes %25 on the second pass. The decode-once test with the URL Encoder/Decoder settles any argument about whether it happened, and encoding the raw value exactly once is the fix that stays fixed. Which characters force all this encoding in the first place is covered in Which Characters Must Always Be Encoded in a URL. For more tools like these, see the Developer Tools guide archive.