Percent-encoding looks arbitrary from the outside. One Polish letter turns into six characters, an escaped slash refuses to decode, a space shows up as %20 in one log and as + in another, and the same link comes out differently from a browser and from a script. None of this is random. Every encoder answers the same five questions, and the answers come from documents written over three decades: RFC 1630 (Tim Berners-Lee, CERN, 1994), the IETF's later RFC 3986, the HTML forms specification, ECMA-262 and the WHATWG URL Standard.
When two systems disagree about a URL, they almost always answered one of these questions differently. The sections below take the questions in the order an encoder meets them.
Question 1: which bytes does the text become?
A URL carries bytes, not letters, so text has to become bytes before anything is escaped. RFC 3986 §2.5 says that for textual data in a new URI scheme, “the data should first be encoded as octets according to the UTF-8 character encoding [STD63]; then only those octets that do not correspond to characters in the unreserved set should be percent-encoded.” In JavaScript the UTF-8 step is not optional: the ECMA-262 Encode operation always converts each code point to UTF-8. Every byte outside the allowed set then becomes % followed by two hex digits for that byte's value.
Encode ł as a URL component in the URL Encoder / Decoder and the Encoded fragments tile reports 2, not 1. The Input bytes tile shows 2 and the Output bytes tile shows 6. All three numbers are correct: ł is U+0142, and UTF-8 stores it in two bytes, 0xC5 and 0x82, so it needs two escapes.
char UTF-8 bytes percent-encoded
a 61 a (unreserved, left alone)
é C3 A9 %C3%A9
ł C5 82 %C5%82
€ E2 82 AC %E2%82%AC
The byte tiles count UTF-8 bytes, not characters, and the fragment count is the number of %XX triplets. Each escaped byte becomes exactly three ASCII characters, so the output is at most three times the input's byte size. Measured in characters, non-ASCII text grows the most: one CJK character, stored as three UTF-8 bytes, becomes nine.
The answer to this question used to be different. RFC 1630, dated June 1994, says that characters not allowed in a URI “may be represented in the URL by a percent sign “%” immediately followed by two hexadecimal digits (0-9, A-F) giving the ISO Latin 1 code for that character.” The legacy escape() and unescape() functions still exist, but only in ECMA-262 Annex B, which collects features kept for compatibility with existing pages. They skip the UTF-8 step, so their output for non-ASCII text does not match what servers and browsers expect today.
Some text cannot become UTF-8 at all. JavaScript strings are UTF-16, and a character outside the Basic Multilingual Plane, such as most emoji, is stored as two surrogate halves. Code that slices a string between the halves leaves a lone surrogate, which has no code point to convert, so encodeURIComponent throws a URIError. If a value like that reaches the encoder, the tool reports an error and clears the output. MDN suggests String.prototype.toWellFormed() to repair such strings first.
Question 2: which characters may stay as they are?
RFC 3986 sorts the ASCII characters a URI may contain into three groups, plus % itself, which only introduces an escape (§2.2 and §2.3):
| Group | Characters | Role |
|---|---|---|
| Unreserved | A–Z a–z 0–9 - . _ ~ |
Always data. Never needs escaping. |
| gen-delims | : / ? # [ ] @ |
Separate the main parts: scheme, authority, path, query, fragment. |
| sub-delims | ! $ & ' ( ) * + , ; = |
Separate pieces inside a part, such as key=value&key=value. |
Everything else has to be percent-encoded: space, a literal % that is data rather than the start of an escape (written %25), <, >, " and every non-ASCII byte.
A reserved character means something only where it acts as a delimiter. Encode it and it becomes plain data. That is why /docs/a/b and /docs/a%2Fb are different paths: in the second, the last segment is the literal text a/b. RFC 3986 states that URIs differing only in whether a reserved character is percent-encoded are not equivalent. Unreserved characters are the opposite case: §6.2.2.2 says %7E and ~ are equivalent, and normalizers are expected to decode such escapes.
Only the code that builds a URL knows which / or & is structure and which is data, so the encoder has to be told what it is looking at. JavaScript offers that choice as two functions, both defined in the ECMA-262 URI handling functions:
encodeURIComponenttreats its input as data. It leaves only ASCII letters, digits and- _ . ! ~ * ' ( )unescaped.encodeURItreats its input as a whole address. It also leaves; , / ? : @ & = + $ #unescaped, so the structure survives.
The tool's URL component mode calls encodeURIComponent and decodeURIComponent, and Full URL mode calls encodeURI and decodeURI:
URL component: a&b=1
→ a%26b%3D1
Full URL: https://example.test/a path?q=a&b=1
→ https://example.test/a%20path?q=a&b=1
In the first case & and = are data, so they are escaped. In the second they are delimiters, so only the space changes.
Neither function matches RFC 3986 exactly. encodeURI escapes [ and ], which RFC 3986 uses around IPv6 literals such as http://[::1]/, and MDN's encodeURI page shows how to restore them. encodeURIComponent leaves ! ' ( ) * alone, although RFC 3986 classifies them as sub-delims that a scheme may give a meaning. If your target needs them escaped, use a stricter helper like the one on MDN's encodeURIComponent page.
Why %2F survives decodeURI
The same question applies in reverse, which makes decoding deliberately asymmetric. ECMA-262 specifies that decodeURI does not decode escapes of reserved characters or #. So %26, %2F, %3F and %23 stay as they are, while %20 and %C5%82 are decoded. If %2F became /, one path segment would silently become two, and the address would point somewhere else. Escaped unreserved characters such as %7E are decoded (to ~), because decoding them cannot change the structure.
Case is a separate matter. RFC 3986 §2.1 treats the hex digits as case-insensitive, so %2f and %2F both represent the byte 0x2F, and §6.2.2.1 lists uppercasing as a normalization step. Both still differ from a literal /.
This asymmetry makes decodeURI useful for comparing two versions of an address. Put the raw strings side by side, note which escapes differ, then decode both in Full URL mode in the URL encoder. Because reserved escapes survive, identical results usually mean the same text and the same structure. Two cases still need a manual look. decodeURI does decode %25, so a%252F and a%2F both come out as a%2F, although the first holds the literal text %2F and the second an encoded slash. It also keeps the hex case of reserved escapes, so %2f and %2F decode differently even though RFC 3986 treats them as the same escape.
Question 3: what does a space look like?
RFC 1630 already warned that white space is “risky in URIs to be printed or sent by electronic mail”, called the choice of escape character “a matter of taste” and settled on %. The same document added a second spelling: “within the query string, the plus sign is reserved as shorthand notation for a space. Therefore, real plus signs must be encoded.”
The URI specifications that followed, RFC 1738 in December 1994, RFC 2396 and RFC 3986 in January 2005 as STD 66, never made + a general space. HTML forms kept it alive: the application/x-www-form-urlencoded format in HTML 4.01 §17.13.4.1 (a W3C Recommendation of 24 December 1999) replaces spaces with +, replaces other non-alphanumeric characters with %HH, the two digits giving the character's ASCII code, and writes line breaks as %0D%0A.
Today the WHATWG URL Standard defines the format. Its percent-encode set leaves only ASCII alphanumerics and * - . _ unescaped, and its serializer writes space as +. The URLSearchParams API uses this serializer, so new URLSearchParams({q: 'a b'}).toString() gives q=a+b, while encodeURIComponent('a b') gives a%20b.
encodeURIComponent |
encodeURI |
form-urlencoded | |
|---|---|---|---|
| Left unescaped | letters, digits, - _ . ! ~ * ' ( ) |
the same plus ; , / ? : @ & = + $ # |
letters, digits, * - . _ |
| Space | %20 |
%20 |
+ |
Literal + |
%2B |
+ (left as is) |
%2B |
+ when decoded (decodeURIComponent / decodeURI / form parser) |
stays + |
stays + |
becomes a space |
So + means a space only inside form-encoded data. q=hello+world and q=hello%20world can both be correct for the same text, depending on whether the receiving code parses the query as a form. A generic decoder such as decodeURIComponent reads + as a plus sign.
In the tool, Query value gives the same output as URL component: a space becomes %20, and + is decoded as a literal plus sign. If your server expects form encoding, replace %20 with + yourself or build the query with URLSearchParams.
Question 4: who decodes, and how many times?
Both encodeURI and encodeURIComponent escape % itself, so an already encoded %20 becomes %2520. The tool does the same when encoding, whichever conversion type you pick, so do not encode input that is already encoded. RFC 3986 §2.4 is direct: implementations “must not percent-encode or decode the same string more than once”.
The rule has a security side. OWASP's double-encoding page gives the classic example:
%252e%252e%252f → first decode → %2e%2e%2f → second decode → ../
A filter that decodes once and looks for ../ sees nothing suspicious. A later layer that decodes again produces a path traversal. The defence follows from §2.4: decode to the canonical form once, then validate. If the real problem is a URL nested inside another URL's query string, the guide on nested URLs, ampersands and double encoding walks through the practical fix.
Decoding can also meet input that is not a valid escape at all, and ECMA-262 makes both failure types throw a URIError. The first is a malformed or truncated escape, such as 100% (a % with nothing after it) or %E0%A4%A (the last escape is missing a digit). The second is well-formed escapes that are not valid UTF-8: %80 is a continuation byte with no lead byte, which is why %C5%82 decodes and %80 does not. In both cases the tool shows “This percent-encoded value is incomplete or invalid.” and clears the output. It never guesses whether you meant to encode or decode; it uses the direction you selected.
Question 5: whose rulebook does the receiver follow?
Browsers do not implement RFC 3986 directly. They implement the WHATWG URL Standard, a living standard whose stated goals include aligning RFC 3986 and RFC 3987 with contemporary implementations and obsoleting them. Instead of one reserved set, it defines a percent-encode set per context, including C0 control, fragment, query, special-query, path, userinfo, component and application/x-www-form-urlencoded.
The two rulebooks do not always agree. Daniel Stenberg, who maintains curl, keeps a URL interop document on “where and how RFC 3986, RFC 3987 and the WHATWG URL Specification differ.” Under RFC 3986 a space is not a valid URI character, so an RFC-style parser rejects it or stops there, while the WHATWG parser accepts it and sends it as %20. RFC 3986 does not treat a backslash as a slash (it is not a valid URI character at all), while WHATWG converts it to a slash in web URLs. A browser and an RFC 3986 client can therefore turn the same typed input into different URLs. Where does a URL end? covers this parser split in detail.
In Full URL mode the tool shows a Host, Path, Query and Fragment breakdown, produced by the browser's own URL parser rather than by the page. For https://example.test/a path?q=a&b=1 it reads Host example.test, Path /a%20path, Query ?q=a&b=1 and Fragment —. A relative URL such as /a path cannot be parsed without a base, so no breakdown appears.
To check what the browser itself will send, compare the encoded result with new URL(...).href rather than with the address bar, which often displays a decoded, human-readable form and can hide real differences. The conversion runs in your browser and nothing is sent over the network, which matters because URLs often carry access tokens and session IDs.
Reading an escape backwards
When a URL looks wrong, the odd-looking part usually points to the question that was answered differently:
| You see | Question that went differently |
|---|---|
%C5%82 for ł |
1: text became UTF-8 bytes, one escape per byte |
A URIError on encode |
1: a lone surrogate has no UTF-8 form |
%26 where you typed & |
2: the value was encoded as data, not structure |
%2F that will not decode |
2: decodeURI protects reserved escapes |
+ instead of %20 |
3: form encoding, not generic URI encoding |
%2520 |
4: something encoded an already encoded string |
A URIError on decode |
4: malformed escape or invalid UTF-8 |
| Browser and script disagree | 5: WHATWG parser versus RFC 3986 |
Percent-encoding escapes only the bytes that need it, so hello world stays mostly readable, which suits text going into a URL. For arbitrary binary data, Base64 re-encodes every byte into a fixed alphabet, predictable in size but unreadable; the Base64 encoder handles that case. Neither is encryption, and anyone can reverse both. For building URLs in code, the safest choice is usually not to call an encoder by hand at all: the URL and URLSearchParams APIs apply the WHATWG rules for each part of the address, which is what the browser will do with it anyway.