Spaces, symbols, and special characters can't travel safely in a URL as-is. Here's the actual rule for what gets encoded and why.
Search for something with a space in it and look at the address bar afterward, and you'll almost always see %20 sitting where the space used to be. That's URL encoding — sometimes called percent-encoding — doing exactly what it's designed to do: making sure a URL only ever contains characters that are guaranteed to survive being transmitted across the internet's various systems intact.
A URL has structural characters with specific meaning — `/` separates path segments, `?` starts the query string, `&` separates parameters, `#` marks a fragment. If the actual data you wanted to put in a URL happened to contain one of those characters literally, it would break the URL's structure or get misinterpreted. Spaces are similarly problematic, though for a different historical reason: they were never considered a safe or valid part of the standard character set for URLs, since they could be ambiguous when a URL was passed around in whitespace-sensitive contexts like plain text or command lines.
The rule is mechanical: take the character's byte value, convert it to hexadecimal, and prefix it with a percent sign. A space is byte value 32, which is 20 in hexadecimal — hence %20. An ampersand (&) is byte value 38, hex 26, so it becomes %26 when it needs to appear as literal data rather than as the query-string separator it normally is. This is why encoding matters most for characters that already mean something structurally in a URL: encoding them tells the receiving system "treat this as literal data, not as part of the URL's syntax."
Letters, numbers, and a small set of punctuation (like hyphens, underscores, and periods) are considered "unreserved" and never need encoding. Reserved characters — the ones with structural meaning like `/ ? # & =` — need encoding whenever they appear as literal data rather than in their structural role. Non-ASCII characters (accented letters, emoji, non-Latin scripts) always need encoding, since a URL is technically restricted to a subset of ASCII, and anything outside that set gets converted to its UTF-8 byte representation and then percent-encoded byte by byte.
If you're building a URL programmatically and inserting user-provided data into it, always encode that data before insertion — skipping this is a common source of broken links and, in web applications, a real security risk if malicious input isn't properly encoded.
Search engine query strings, API requests passing user input as URL parameters, and sharing a link that contains special characters (an email address with a + sign, a search term with an ampersand) are all places you'll encounter or need URL encoding directly. Most modern browsers and frameworks handle this automatically for normal navigation, but manual encoding still comes up regularly when constructing URLs programmatically or debugging why a link with unusual characters isn't working as expected.
The + character is a legacy convention specifically for encoding spaces within a URL's query string (the part after the ?), a holdover from older form-submission standards, while %20 is the general-purpose encoding valid anywhere in a URL.
Yes — any character outside the basic unreserved set, including accented letters and non-Latin scripts, gets converted to UTF-8 bytes and then percent-encoded.
No — it's purely a way to safely represent characters within a URL's syntax. Anyone can decode it instantly; it provides no confidentiality or security on its own.
The last part of a URL does more SEO and usability work than its size suggests. Here's how to write one well.
Regular expressions are powerful and famously unreadable. Here's how to build one up piece by piece instead of guessing blindly.
That 36-character string of hex digits and dashes shows up in database records, API responses, and file names everywhere. Here's why.
JWTs show up in almost every modern login system. Here's what the three parts actually mean, and what a JWT can't do for you.