Developers
URL Encoding Explained: What %20 and %3D Mean
Learn why web addresses use codes like %20, how percent-encoding works, when to encode a value or a whole URL, and how to avoid double encoding.
Published · 6 min read
Paste a link with a space in it into a chat and it often turns into something like my%20report.pdf. A search address may contain %3D and %26 in places where you expected an equals sign and an ampersand. These codes are not errors. They are the way the web writes characters that a URL cannot carry safely, and understanding them saves a lot of debugging time.
This guide explains what URL encoding is, how it works, which part of a link you should encode and the mistakes that cause broken links.
Why URLs need encoding
A web address can only contain a limited set of characters: letters, digits and a few symbols. Several other characters have special jobs inside a URL:
- A question mark starts the query string.
- An ampersand separates one parameter from the next.
- An equals sign joins a parameter name to its value.
- A hash sign starts the fragment, the part that points to a place on the page.
- A slash separates the parts of a path.
The rules for these characters are set out in the URI standard, RFC 3986. It defines unreserved characters that are always safe: letters, digits, hyphen, period, underscore and tilde. Reserved characters keep their special meaning. Everything else, such as spaces, quotes and non-English letters, has to be written in a safe form.
Problems appear when your data contains a reserved character. Imagine a search for "fish & chips". If you put it into the address as q=fish & chips, the ampersand looks like the start of a new parameter, and the search receives only "fish". Encoding fixes this by turning the ampersand in your data into a harmless code.
How percent-encoding works
URL encoding is also called percent-encoding because every unsafe character becomes a percent sign followed by two hexadecimal digits. Those digits are the value of the byte.
- A space is byte 20 in hexadecimal, so it becomes %20.
- An ampersand becomes %26.
- An equals sign becomes %3D.
- A question mark becomes %3F.
- A percent sign itself becomes %25.
Letters outside plain English use their UTF-8 bytes, and each byte gets its own code. The UTF-8 standard is RFC 3629. The word café becomes caf%C3%A9, because the letter é takes two bytes, C3 and A9. The Urdu word اردو becomes %D8%A7%D8%B1%D8%AF%D9%88, four letters of two bytes each.
Decoding reverses the process. Every %XX group turns back into its byte, and the bytes are read as text again. If a percent sign is not followed by two valid hexadecimal digits, the text is not valid percent-encoding, and many programs report a "malformed URI" error.
Encode the value, not the whole address
The most useful rule is to encode the piece you are inserting, not the finished link. There are two modes, and the difference is easy to see with one example.
Suppose the text is name=Ali Khan&city=Multan.
- Encoding it as a value gives name%3DAli%20Khan%26city%3DMultan. The equals sign and the ampersand are encoded too, so the whole string now counts as one piece of data. This is right when you place it inside one parameter.
- Encoding it as a complete URL gives name=Ali%20Khan&city=Multan. The structure characters stay as they are, and only the space is changed. This is right when the structure is already correct and you only need to clean it up.
Here is a full address with spaces: example.com biryani&sort=price asc. Encoded as a complete URL it becomes example.com, and it still works. Encoded as a value, the colon, the slashes and the question mark would all turn into codes, and the link would stop being a link.
The practical rule is this: encode each value separately, then assemble the URL. In JavaScript, encodeURIComponent is for a single value and encodeURI is for a complete address.
The plus sign and spaces
Spaces cause the most confusion because there are two styles. In a normal URL, a space is %20. In data sent from an HTML form, the older form encoding writes a space as a plus sign. You will see both in the wild, for example q=lahore+biryani and q=lahore%20biryani, and servers that read query strings usually accept either.
This creates a trap for the plus sign itself. If your data contains a real plus, such as the text a+b=c, and you leave it unencoded, a form-style reader can treat it as a space. Encode it as %2B, and the text becomes a%2Bb%3Dc. Inside the path of a URL, a plus is just a plus, so the rule applies to query strings.
When decoding, decide which style the text uses. Turning every plus into a space is correct for form data and wrong for a plain path.
Double encoding
Double encoding happens when the same text is encoded twice. The first pass turns a space into %20. The second pass sees the percent sign and encodes it as %25, so you get %2520.
For example, "a b" becomes a%20b, and encoding it again gives a%2520b. The link now asks for a file called "a%20b" rather than "a b". If you see %25 followed by two digits in a URL, double encoding is the likely cause. Find the step that encodes twice, often a library plus a manual call, and remove one of them.
The opposite error, not encoding at all, shows up as links that break at the first space or ampersand. Text such as 100% sure needs its percent sign encoded, and the right result is 100%25%20sure.
A quick checklist
- Encode values one at a time, using the value mode, before you build the URL.
- Use the complete-URL mode only to clean an address whose structure is already correct.
- Encode a literal plus sign as %2B in query strings.
- Look for %25 as a sign of double encoding.
- Test the final link by opening it, not only by reading it.
URL encoding is not the same thing as Base64. Percent-encoding keeps readable text readable and only replaces unsafe characters. Base64 rewrites the whole content in a different alphabet, which is covered in Base64 Encoding Explained in Plain English.
Encode and decode a string
The URL Encode/Decode tool converts text in both directions. We tested every example in this guide with the same encoding functions it uses. Choose whether you are converting a single value or a complete URL, paste your text and copy the result. A switch lets you write spaces as plus signs or treat plus signs as spaces.
When you need a different kind of text conversion, the Base64 Encode/Decode tool handles Base64 in the same way.
Try it yourself
Free, private and it runs in your browser.