What URL encoding does
URLs can only contain a limited set of ASCII characters. Everything else, including spaces, accented letters and characters that have a job inside a URL like &, = and ?, is written as % followed by the hex value of each UTF-8 byte. A space becomes %20 and é becomes %C3%A9. This is called percent-encoding.
Query value or whole URL?
Query value works like JavaScript’s encodeURIComponent. It encodes every reserved character, so use it for one parameter value or path segment. Encoding a&b=c gives a%26b%3Dc, which can safely sit inside ?q=….
Whole URL works like encodeURI. It leaves : / ? # & = alone so the URL still works, and only encodes spaces and non-ASCII characters. Don’t use it for parameter values: an & inside a value would split it into two parameters.
Plus signs and spaces
HTML forms send spaces as + (the application/x-www-form-urlencoded format), while the rest of the URL uses %20. If a decoded value has + where you expected spaces, turn on “Treat + as space”. If a literal plus sign is getting lost (a common bug with phone numbers like +91…), the sender needs to encode it as %2B.
Double encoding
Seeing %2520 in a URL means it was encoded twice: % itself became %25. Decode once and check the result. Usually a library is encoding parameters for you and the code encodes them again first.
In code
// JavaScript: build query strings with URLSearchParams
const qs = new URLSearchParams({ q: "café & bar", page: "2" }).toString();
// "q=caf%C3%A9+%26+bar&page=2"
// Java
URLEncoder.encode("café & bar", StandardCharsets.UTF_8); // "caf%C3%A9+%26+bar"
// Python
from urllib.parse import quote, urlencode
quote("café & bar") # 'caf%C3%A9%20%26%20bar'
urlencode({"q": "café & bar"}) # 'q=caf%C3%A9+%26+bar'