What percent-encoding does, and why the same text can be encoded three ways
A URL may contain only a small set of ASCII characters. Everything else, from a space to é or 東, is first turned into bytes, and each byte is written as % and two hexadecimal digits (RFC 3986, section 2.1). In UTF-8, which almost every site uses today, é is two bytes and becomes %C3%A9, and 東京 is six bytes and becomes %E6%9D%B1%E4%BA%AC. Decoding reverses those steps, so the decoder has to know which character set produced the bytes: %93%8C%8B%9E reads as 東京 in Shift_JIS and as unreadable symbols in UTF-8.
Encoding depends on where the text will go. A query value or path segment (encodeURIComponent in JavaScript) must encode &, =, / and ? so that they are not read as separators: a b&c=d/é becomes a%20b%26c%3Dd%2F%C3%A9. A whole address (encodeURI) keeps those characters, because they give the URL its structure: a%20b&c=d/%C3%A9. HTML forms send application/x-www-form-urlencoded data, where a space is + and only * - . _ stay as they are: a+b%26c%3Dd%2F%C3%A9. All three results come from this page.
Older Japanese, Korean and Chinese sites, mail systems and search logs still use Shift_JIS, EUC-JP, EUC-KR, GBK or Big5. Browsers can read these sets but write only UTF-8, so this page builds its encoding tables from the browser’s own decoder: 検索 東京 becomes %8C%9F%8D%F5%20%93%8C%8B%9E in Shift_JIS and %E6%A4%9C%E7%B4%A2%20%E6%9D%B1%E4%BA%AC in UTF-8. When a line is not valid UTF-8, the page tries the other sets and previews each one that reads it. Short byte strings can be valid in more than one set, and only a person can tell which reading makes sense.
Two problems turn up in real links. A link encoded twice shows %2520 where a space should be, because the % of %20 was encoded again as %25; the page notices escapes left in the result and offers to decode again, up to five rounds. A % that is not followed by two hex digits, as in 100% sure, is kept as a literal %, the way browsers treat it, and counted so you can check it. In our test run, decoding 9,000 analytics links (844,889 characters) took 48 ms and encoding 1,050,000 characters took 0.11 s. The editor holds up to 2,000,000 characters and works on long texts in a background thread.