Percent-encoding without surprises
URLs are text, but not every character is allowed in every position. Percent-encoding replaces unsafe bytes with % and two hex digits: a space becomes %20, a slash inside a query value becomes %2F, and so on.
Path versus query
The rules differ by component. In a path, / separates segments and must be encoded if it is part of a value. In a query string, & and = are separators and must be encoded inside values. Encoding a whole URL with one function is a common source of broken links.
Space: %20 or +?
In query strings, + traditionally means a space — that comes from HTML form encoding. In paths, + is a literal plus. Modern code should prefer %20 everywhere and treat + as a space only when parsing form-encoded bodies.
Double encoding
Encode once, at the moment the value becomes part of a URL. If a proxy, a template engine and a client library each encode the same value, %20 becomes %2520 and the server sees a literal %20. When a URL looks wrong, decode it step by step and count the layers.
Unicode
Non-ASCII characters are encoded as UTF-8 bytes, then percent-escaped: привет becomes %D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82. If the receiving side assumes a different charset, the text turns into mojibake — the classic symptom of a missing charset=utf-8.
Use the URL tool to encode and decode values while debugging; it uses the same rules as encodeURIComponent in JavaScript.