If you have ever copied a link and seen %20, %26 or %C3%A9 in it, you have met URL encoding, also called percent-encoding. It is how web addresses safely carry spaces, symbols and non-English letters. Getting it wrong causes broken links, missing search terms and confusing API errors.
This guide explains how URL encoding works and when to use it, with examples you can try in the free freetoolza URL Encoder & Decoder.
Why URLs need encoding
A URL has structure. Characters such as /, ?, &, = and # have special jobs: they separate the path, start the query string, split parameters and mark a fragment. If your data contains one of those characters, the browser or server cannot tell whether it is part of the data or part of the structure.
Consider a search for salt & pepper. Written raw, the link /search?q=salt & pepper is read as a parameter q=salt followed by a second, nameless parameter. Encoded, it becomes /search?q=salt%20%26%20pepper, and the server receives exactly what the user typed.
How percent-encoding works
Each unsafe character is replaced by a percent sign followed by two hexadecimal digits representing its byte value. A space is byte 32, which is 20 in hexadecimal, so it becomes %20. Characters outside basic ASCII are first converted to UTF-8 bytes, and each byte is encoded. That is why é becomes two codes, %C3%A9, and many Hindi or emoji characters become three or four.
| Character | Encoded | Why it matters |
|---|---|---|
| space | %20 | Spaces are not allowed in URLs |
& | %26 | Separates query parameters |
= | %3D | Separates a parameter name from its value |
? | %3F | Starts the query string |
/ | %2F | Separates path segments |
# | %23 | Starts the fragment; the browser does not send it to the server |
+ | %2B | Can be read as a space in form-style query strings |
% | %25 | The escape character itself |
Some characters never need encoding. The URL standard (RFC 3986) calls them unreserved: the letters A–Z and a–z, digits 0–9, and the four symbols - . _ ~.
Encode a whole URL or just one value?
This is the most common source of bugs, and it is why the freetoolza encoder offers two modes, matching the two JavaScript functions:
- Component (
encodeURIComponent): use for a single value, such as a search term, a name or a redirect address placed inside a parameter. It encodes structural characters such as&,=,/and?so they cannot break the URL. - Full URL (
encodeURI): use when you have a complete address and only want to make spaces and unsafe characters safe. It leaves:,/,?,#,&and=intact so the structure still works.
Rule of thumb: build the URL from parts, and encode each value with component encoding. Never run component encoding on a whole URL, or https:// turns into https%3A%2F%2F.
// JavaScript
const term = "salt & pepper";
const url = "https://example.com/search?q=" + encodeURIComponent(term);
// https://example.com/search?q=salt%20%26%20pepper
// Even better: let the browser build the query string
const u = new URL("https://example.com/search");
u.searchParams.set("q", term); // handles encoding for you
# Python
from urllib.parse import quote, urlencode
quote("salt & pepper", safe="") # 'salt%20%26%20pepper'
urlencode({"q": "salt & pepper"}) # 'q=salt+%26+pepper'
%20 or +? Two ways to encode a space
You will see spaces written as %20 and sometimes as +. HTML forms submit data in a format where + means space in the query string, which is why Python’s urlencode produces salt+%26+pepper. In the path part of a URL, however, + is a literal plus sign. %20 works everywhere, so it is the safer choice when you encode by hand.
The double-encoding bug
If you encode text that is already encoded, the percent signs themselves get encoded: %20 becomes %2520. The server then receives the literal text “%20” instead of a space. If you see %25 followed by two hex digits in your logs, something is encoding twice. Decode once with the URL Decoder to check what the value really is, and make sure only one layer of your code does the encoding.
Try it: encode and decode in the browser
- Open the URL Encoder & Decoder.
- Paste your text and choose Component for a single value or Full URL for a complete address.
- Click Encode or Decode. Use Use output as input to run the result through again, for example to decode a value that was encoded twice.
Testing an API? The Demo REST API accepts query parameters, so you can see how encoded values behave in a real request, and the JSON Formatter makes the response readable.
Frequently asked questions
Is URL encoding a form of security or encryption?
No. It is a reversible formatting step that anyone can decode. Never use it to hide passwords or tokens.
Why does my browser’s address bar show spaces and accents?
Browsers often display decoded, readable text for convenience, but they send the encoded form to the server. Copying the link usually gives you the encoded version.
Do I need to encode hyphens or underscores?
No. Letters, digits, hyphens, periods, underscores and tildes are always safe in URLs.


