Learn · Guide
URL Encoding Basics
Why spaces become %20, and when to encode a query value by hand.
Percent encoding in one sentence
A URL can only carry a limited set of characters safely. Anything outside that set is written as a percent sign followed by two hex digits: a space becomes %20, and & becomes %26. The browser usually does this for you when you submit a form, but it becomes visible when you build a link in code or paste one into a chat.
Query parameters are separate values
In ?q=red+shoes&sort=price, the separators are ?, & and =. The value red shoes is encoded as red+shoes in a form query, or as red%20shoes in a path. Both forms decode to the same string. Trouble starts when a value itself contains & or =: without encoding, the server reads those as separators and your value is cut in half.
Do not encode twice
Encoding a string twice is the most common bug. a b becomes a%20b, then a%2520b, because the percent sign in %20 is encoded again as %25. If a link shows %25 where you expected a space, look for a second encode call. Decode exactly once on the server, and let the framework handle the rest.
Try it locally
Open the URL codec and encode red shoes & sizes, then decode the result. Paste the encoded value into a query string and watch how the separators stay intact. A few minutes with a codec removes most of the guesswork from hand-built links.
Paths, fragments and form bodies behave differently
Encoding rules depend on where the text sits. In a path segment, a slash is a separator, so a value containing a slash must be encoded or it becomes a new segment. In a query, the plus sign is commonly read as a space, while %2B is a literal plus. In a fragment after #, the browser does not send the text to the server at all, so the same string can be treated differently by the client and the server. Form bodies use their own rules again: application/x-www-form-urlencoded uses plus for spaces, while JSON bodies carry raw strings and are encoded by the transport. When a link behaves strangely, first identify which part of the URL changed the value, then encode only that part.