URL Encoding Explained: What %20 and Other Codes Mean
By Urlzee Team · Published · 6 min read
URL encoding, also called percent-encoding, replaces characters that are not allowed in a URL, or that have a special meaning in one, with a percent sign followed by two hexadecimal digits. %20 is a space, %26 is an ampersand, %2F is a slash. It lets any text travel safely inside a web address.
Why do URLs need encoding?
URLs need encoding because a small set of characters does structural work, and data must not be mistaken for structure. A ? begins the query string. An & separates parameters. A # begins the fragment. A space is not permitted at all.
Suppose you want to pass the search term salt & vinegar in a query:
https://example.com/search?q=salt & vinegar
A server reading this sees a parameter q with the value salt , followed by a second, nameless parameter. The spaces are invalid on top of that. Encoded, the meaning is unambiguous:
https://example.com/search?q=salt%20%26%20vinegar
Now the & is plainly part of the value. For a refresher on which part of an address is which, see anatomy of a URL.
How does percent-encoding work?
Each character is converted to its byte value and written as % plus two hex digits. A space is byte 32 in decimal, which is 20 in hexadecimal, so it becomes %20.
Characters outside basic ASCII are first converted to bytes using UTF-8, and then every byte is encoded. That is why one visible character can turn into several codes:
| Character | UTF-8 bytes | Encoded |
|---|---|---|
é | C3 A9 | %C3%A9 |
ñ | C3 B1 | %C3%B1 |
€ | E2 82 AC | %E2%82%AC |
日 | E6 97 A5 | %E6%97%A5 |
So café in a path is caf%C3%A9. Browsers often display the readable form in the address bar while sending the encoded form to the server, which is why a link can look tidy on screen and expand into a wall of percent signs when pasted elsewhere.
Which characters are safe, and which must be encoded?
The standard that defines URL syntax, RFC 3986, sorts characters into three groups.
Unreserved characters never need encoding:
A–Z a–z 0–9 - . _ ~
Reserved characters have a structural role. They are left alone when doing that job and must be encoded when they appear as data:
: / ? # [ ] @ ! $ & ' ( ) * + , ; =
Everything else must always be encoded: spaces, quotation marks, angle brackets, the percent sign when it is meant literally, and any non-ASCII character.
The middle group is the one that causes confusion, because the right answer depends on position. A / between path segments is structure and stays as it is. A / inside a query value, such as a date written 01/02/2027, is data and should be %2F.
What do the common URL codes mean?
These are the codes you will meet most often.
| Code | Character | Notes |
|---|---|---|
%20 | space | Also written + in form-encoded query strings |
%22 | " | |
%23 | # | Unencoded, it starts the fragment |
%25 | % | A literal percent sign |
%26 | & | Unencoded, it separates query parameters |
%2B | + | Encode a real plus sign in queries |
%2C | , | |
%2F | / | Unencoded, it separates path segments |
%3A | : | |
%3D | = | Unencoded, it separates a name from its value |
%3F | ? | Unencoded, it starts the query string |
%40 | @ | |
%0A | line feed | A line break |
What is the difference between %20 and + for spaces?
%20 is a space everywhere in a URL; + is a space only in a query string that follows the form-encoding convention. That convention, application/x-www-form-urlencoded, comes from HTML forms and is why a search for red shoes commonly appears as ?q=red+shoes.
Two consequences follow:
- In a path, a
+is a plus sign./files/a+b.pdfis a file calleda+b.pdf. - In a query, a literal plus sign must be written
%2B, otherwise it may be read as a space. This catches people out with phone numbers (+44...), email addresses that contain plus tags, and timestamps with time zone offsets.
If you are unsure, use %20 for spaces and %2B for plus signs. That reading is correct in every part of the URL.
What is double encoding, and how do you fix it?
Double encoding is what happens when an already encoded URL is encoded again. The percent sign in %20 is itself converted to %25, giving %2520. The destination decodes once, gets the literal text %20, and shows it on the page or fails to find the resource.
Signs of it:
%2520where a space should be%253A%252F%252Fwhere://should be%2526where an&should be
It tends to creep in when a tool encodes an address you had already prepared. The fix is to work out which step encoded it a second time and remove that step. Encode each value exactly once, at the moment you put it into the URL.
Deliberately nested URLs are a legitimate case where one level of encoding is required. To pass https://example.com/a?b=1 as a parameter, it must be encoded so its own ? and = do not interfere:
https://example.org/go?to=https%3A%2F%2Fexample.com%2Fa%3Fb%3D1
How do you encode a URL correctly?
Encode the individual values, never the whole address. If you run an entire URL through an encoder, the ://, slashes and question mark get encoded too, and the result is not a usable link.
In JavaScript:
const term = "salt & vinegar";
const url = "https://example.com/search?q=" + encodeURIComponent(term);
// https://example.com/search?q=salt%20%26%20vinegar
encodeURIComponent is for a single value and encodes reserved characters. encodeURI is for a complete URL and leaves reserved characters alone, so it will not protect an & inside a value.
In Python:
from urllib.parse import quote, urlencode
quote("salt & vinegar", safe="") # 'salt%20%26%20vinegar'
urlencode({"q": "salt & vinegar"}) # 'q=salt+%26+vinegar'
urlencode uses the form convention, so spaces become +.
Without code, let a tool assemble the URL. The UTM builder takes care of the punctuation when you add campaign parameters, so you fill in fields instead of typing ?, & and = yourself.
Does URL encoding matter when you shorten a link?
It matters for the destination, and the short link itself avoids the problem. A short link contains only simple characters, so there is nothing in it to encode or mangle. That is one of its practical advantages: an address full of %C3%A9 and %26 is exactly the kind that gets broken by line wrapping or an app that stops linking at an unusual character.
When you paste a long address into the URL shortener, paste it as copied from your browser. Do not encode it first; that risks double encoding. Then test the short link and look at the final address. If a parameter is missing or a value is cut off, the original URL probably had an unencoded &, # or space in a value. The link checker shows the final URL a link resolves to, which helps you see what the destination actually received.
Encoding also explains why some URLs are much longer than they look. Every encoded character takes three, and non-Latin text takes six or more per character. How long can a URL be? covers the limits that can result.
Is URL encoding a form of security?
No. Percent-encoding is formatting, and it can be reversed by anyone with no key at all. It does not hide data and does not make an unsafe URL safe. Attackers sometimes encode parts of a link to make the true destination harder to read at a glance, so if a link's host or path is a mass of percent codes, decode or expand it before trusting it.
Encoding has one job: carrying arbitrary text through a format with strict punctuation.
Frequently asked questions
- What does %20 mean in a URL?
- %20 is the encoded form of a space. URLs cannot contain literal spaces, so each one is replaced by a percent sign followed by 20, the hexadecimal value of the space character.
- What is the difference between %20 and + in a URL?
- Both can stand for a space, but + only means a space inside a query string that uses form encoding. In the path, a + is a literal plus sign, so %20 is the safe choice everywhere.
- Why do I see %25 in my URL?
- %25 is an encoded percent sign. Seeing %2520 or similar usually means the URL was encoded twice, turning the % of %20 into %25.
- Do I need to encode a URL before shortening it?
- Normally no. Copy the address from your browser and paste it as it is. You only need to encode by hand when you are building a URL yourself and a value contains spaces or reserved characters such as & or #.
- Is URL encoding the same as encryption?
- No. URL encoding is a reversible formatting step that anyone can decode instantly. It hides nothing and provides no security.