What Is URL Encoding? Percent-Encoding Explained
Spaces, ampersands and accented letters can break a web address. Learn how percent-encoding turns them into safe sequences like %20, which characters need it, and how to avoid double encoding and other classic bugs.
Copy a link from a search results page and paste it into a chat, and you may see something like q=winter%20boots. That %20 is a space in disguise. Web addresses can only contain a small set of characters, and everything else has to be written in a special way called percent-encoding, or URL encoding. Most of the time the browser does it for you, but when you build links, debug an API or read server logs, knowing how it works saves a lot of confusion.
Why URLs need encoding
A URL is not just text; it has structure. Each part is separated by characters with a fixed meaning:
:and//separate the scheme from the address, as inhttps:///separates folders in the path?starts the query string&separates one parameter from the next=separates a parameter's name from its value#starts the fragment, the part that points inside a page
These are called reserved characters. If a value you put in a URL contains one of them, the URL changes meaning. A search for Tom & Jerry written raw as ?q=Tom & Jerry looks to a server like a parameter q with the value "Tom " and a second, empty parameter named " Jerry". Spaces, quotes, angle brackets and any non-English letters cause similar problems, because they are simply not allowed in a URL at all.
How percent-encoding works
The rule is short:
- Convert the character to its bytes in UTF-8.
- Write each byte as a % sign followed by two hexadecimal digits.
A space is byte 32, which is 20 in hex, so it becomes %20. The ampersand is byte 38, hex 26, so it becomes %26. Letters outside basic English take more than one byte in UTF-8: ü is two bytes, so München becomes M%C3%BCnchen, and the euro sign is three bytes, %E2%82%AC.
Letters, digits and a few marks such as - _ . and ~ never need encoding. These are the unreserved characters, and they are always safe as they are.
A worked example
Suppose you are building a link to a search page and the user typed 50% off & free shipping. Encoding it as a single value gives:
50%25%20off%20%26%20free%20shipping
Every special character has been neutralized:
- The % sign itself became
%25. If it stayed raw, a decoder would try to read% oas a code. - Each space became
%20. - The & became
%26, so it no longer splits the query string.
The finished link is https://shop.example/search?q=50%25%20off%20%26%20free%20shipping, and the server receives exactly the text the user typed.
Encoding a value versus encoding a whole URL
There are two ways to encode, and picking the wrong one is the most common URL bug.
- Component encoding is for a single piece, such as one parameter value. It encodes reserved characters too, so
a+b=cbecomesa%2Bb%3Dcand/cart?step=2becomes%2Fcart%3Fstep%3D2. - Full-URL encoding is for a complete address that is already structured correctly. It leaves the reserved characters alone and only fixes the characters that are not allowed.
https://shop.example/search?q=winter boots&size=10½becomeshttps://shop.example/search?q=winter%20boots&size=10%C2%BD. The slashes, the ? and the & still work.
The rule of thumb: encode each value with component encoding as you build the URL, and only use full-URL encoding to tidy up an address that someone else already put together.
The + versus %20 puzzle
When an HTML form is submitted with the default settings, the browser writes spaces in the query string as +, not %20. So winter+boots%20for+kids from a form means "winter boots for kids". But outside form data, a + is just a plus sign, and the same string decoded strictly is "winter+boots for+kids".
That is why a literal plus in a value must always be encoded as %2B. Otherwise a phone number like +1 555 0100 or a search for "C++" can arrive at the server with the plus signs turned into spaces.
Classic mistakes
- Double encoding. Encoding a string that is already encoded turns each % into %25.
%20becomes%2520, and the user sees "%20" printed on the page instead of a space. Encode once, at the moment you insert the value into the URL. - Not encoding at all. Building links by gluing strings together works in testing with simple words and fails in production on the first name with an apostrophe or an ampersand.
- Decoding reserved characters too early. Turning
%2Fback into/inside a path changes which folder the URL points to. Decode values only after splitting the URL into its parts. - Broken sequences. A % that is not followed by two hex digits, as in
save 50%, cannot be decoded. Neither can an incomplete multi-byte character such as%E2%82with its third byte missing.
Reading a query string
Once encoded, a query string can be hard to read: q=winter+boots&tag=sale&tag=new&redirect=%2Fcart%3Fstep%3D2. Split at each & and decode each side, and it becomes four parameters: q is "winter boots", tag appears twice with "sale" and "new", and redirect is "/cart?step=2". Notice that the redirect value contains its own ? and =; it only survives because it was encoded as a component.
How to use the URL Encoder & Decoder
Choose Encode or Decode, then choose whether you are working with a single value or a full URL. Paste your text, and the URL Encoder & Decoder shows the result as you type. Tick Treat + as a space when you decode form data. If decoding fails, it tells you the position and the broken sequence, so you can fix it quickly. Paste a complete link into the query string parser to see every parameter decoded in a table, including repeated keys in their original order. Everything runs in your browser, so links that contain tokens or personal data stay on your device.
FAQ
Is URL encoding the same as encryption?
No. It only changes how characters are written, and anyone can decode it. Sensitive data such as passwords should never be put in a URL at all, because URLs end up in browser history, server logs and shared screenshots.
Why do some links contain non-English letters directly?
Browsers often display decoded characters in the address bar to make links readable, but they send the percent-encoded form to the server. Domain names use a separate system for non-English letters, so only the path and query are percent-encoded.
Do I need to encode the hyphen or underscore?
No. Hyphens, underscores, periods and tildes are unreserved and safe in any part of a URL. That is one reason clean page addresses use hyphens between words.
Is URL encoding the same as HTML encoding?
No. HTML encoding writes characters as entities such as & so they display correctly inside a web page. URL encoding writes them as % sequences so they travel correctly inside an address. A link inside HTML sometimes needs both.
Related tools
Related guides
What Is Base64 Encoding and How Does It Work?
Base64 turns any data into plain letters and digits so it can travel safely through systems built for text. Learn how the encoding works bit by bit, where you meet it every day and why it is not encryption.
How Subnetting Works: Plan an IPv4 Network Step by Step
Subnetting looks like binary magic until you see the one rule behind it. Learn to size subnets from a device count, keep them aligned and carve one address block into networks of different sizes.
How to Verify a File Checksum With SHA-256 or MD5
A checksum lets you confirm that a download is complete and has not been tampered with. Learn what hashes are, why one changed letter changes everything and how to check a file on any computer.
HEX, RGB and HSL Color Codes Explained
How screens mix red, green and blue, how to read a HEX code by hand, and when HSL or HSV is the easier way to pick and adjust colors.