When a URL needs encoding
A search term, an email address or a redirect URL passed as a parameter must be encoded, or its &, = and ? will break the link. Decoding is the other way round: read a tracking link, a redirect target or an error log full of %2F and %C3%A9.
Component or whole URL
Component mode encodes every reserved character, including & = / ?: use it for one parameter value. Whole-URL mode keeps the structure (://, ?, #, &, =) and encodes the rest: use it for a full address with spaces or accents. Accents and other non-ASCII characters are encoded as UTF-8 bytes, which is what browsers and servers expect.
Reserved vs unreserved characters
Reserved characters (:, /, ?, #, [, ], @, !, $, &, ', (, ), *, +, ,, ;, =) have special meaning in URLs. They should only be encoded when used outside their reserved purpose — for instance, a / in a query parameter value must be encoded as %2F.
Unreserved characters (letters, digits, -, _, ., ~) never need encoding. Encoding them is valid but unnecessary and makes URLs longer.
Common pitfalls
Double encoding is the most common mistake: encoding an already-encoded URL turns %20 into %2520. Always check if your input is already encoded before encoding it again.
The + sign is another source of confusion. In query strings (application/x-www-form-urlencoded), + means space. But in the path component of a URL, + is literal. JavaScript's decodeURIComponent does NOT decode + as a space; here, the "+ = space" switch of Decode does it (on by default): turn it off when the + belongs to a path.