What Is URL Encoding? Percent-Encoding Explained Simply

Close-up of a laptop keyboard on a wooden desk
Photo: “Laptop Computer” by Fernando Arcos · CC0 1.0 · via Openverse (stocksnap)

Short answer

URL encoding, also called percent-encoding, replaces characters that are not allowed or have a special meaning in a web address with a % sign followed by two hexadecimal digits. A space becomes %20, an ampersand becomes %26 and the letter é becomes %C3%A9 (its two UTF-8 bytes). Letters, digits and - . _ ~ never need encoding.

If you have ever copied a link and found %20 or %3D scattered through it, you have seen URL encoding at work. Web addresses are only allowed to contain a small set of characters, and several of those characters (such as ?, & and /) act as separators. Percent-encoding lets a URL carry any text, including spaces, symbols, emoji and Hindi or Chinese script, without confusing browsers and servers.

Why URLs need encoding

The rules for URLs are set out in RFC 3986, the internet standard for Uniform Resource Identifiers, and in the WHATWG URL Standard that modern browsers follow. They split characters into three groups:

The problem appears when your data contains one of the reserved characters. Imagine a search for “Tom & Jerry”. If the ampersand is left as it is, the server reads ?q=Tom & Jerry as a parameter q with the value “Tom ” followed by a second, broken parameter. Encoding it as %26 tells the server the ampersand is part of the text, not a separator.

How percent-encoding works, step by step

Each character that needs encoding is turned into bytes, and each byte is written as % plus two hexadecimal digits. Here is the rupee price “₹500”:

  1. Turn the text into UTF-8 bytes. The rupee sign ₹ is three bytes in UTF-8: E2, 82 and B9 in hexadecimal. The digits 5, 0, 0 are unreserved, so they stay as they are.
  2. Write each byte as %XX. E2 becomes %E2, 82 becomes %82 and B9 becomes %B9.
  3. Join the result. “₹500” becomes %E2%82%B9500.

For plain ASCII characters the byte is simply the character code. A space is code 32, which is 20 in hexadecimal, so it becomes %20. If hexadecimal is unfamiliar, our guide to converting binary to decimal explains number bases. RFC 3986 recommends uppercase hex digits (%2F rather than %2f), although decoders accept both.

Common characters and their codes

CharacterEncodedWhy it matters
space%20Spaces are not allowed in URLs at all
&%26Separates query parameters
=%3DSeparates a parameter name from its value
?%3FStarts the query string
#%23Starts the fragment, which is never sent to the server
/%2FSeparates path segments
+%2BOften read as a space in form data
%%25Marks the start of an encoded byte
é%C3%A9Two UTF-8 bytes
😀%F0%9F%98%80Four UTF-8 bytes

You can check any of these in our free URL encoder and decoder. Paste text, press Encode component, and the result appears instantly in your browser, with nothing uploaded.

Say you want a link that searches a shop for “red shoes & socks” in the city “São Paulo”. Encode each value separately, then join them with the normal separators:

The finished link is https://example.com/search?q=red%20shoes%20%26%20socks&city=S%C3%A3o%20Paulo. Notice that the ?, the & between parameters and the two = signs stay unencoded, because they are doing their normal job. Only the data inside each value is encoded.

Encoding a whole URL vs one component

This is the most common source of bugs. JavaScript has two built-in functions, and they behave differently:

Encoding a full address with encodeURIComponent() breaks it: https://example.com/a b turns into https%3A%2F%2Fexample.com%2Fa%20b, which is no longer a working link. Using encodeURI() on a value lets an ampersand slip through and split your parameter. Our tool offers both modes as separate buttons, Encode component and Encode full URL, plus Parse URL to break a link into its protocol, host, path and parameters.

Plus sign or %20 for spaces?

Both appear in the wild, and the difference comes from HTML forms. When a browser submits a form with the application/x-www-form-urlencoded format, the WHATWG URL Standard says spaces in the query are written as +. In the path part of a URL, a plus is just a plus. So:

When in doubt, use %20, which means a space everywhere. If your data contains a real plus sign, as in “100+5”, encode it as %2B so it is not turned into a space on the way in.

Common mistakes to avoid

Clean URLs need less encoding

For your own pages, the easiest approach is to avoid characters that need encoding in the first place. A readable address such as /blog/what-is-url-encoding/ is easier to share and remember than one full of % codes. Our slug generator turns a title into a lowercase, hyphenated URL slug automatically. When a link has to be printed or shared offline, a QR code generator takes care of encoding it into the code for you.

Frequently asked questions

What is URL encoding in simple words?

It is a way to write characters that are not allowed or have a special meaning in a web address as a percent sign plus two hexadecimal digits, so a space becomes %20 and an ampersand becomes %26.

Why does %20 appear in links?

%20 is the encoded form of a space. Spaces are not allowed in URLs, so browsers and websites replace them with %20, or with a plus sign in form data.

Which characters do not need URL encoding?

Letters A to Z and a to z, digits 0 to 9, and the four symbols hyphen, full stop, underscore and tilde never need encoding.

What is the difference between encodeURI and encodeURIComponent?

encodeURIComponent encodes a single value and also encodes separators such as slash, question mark, ampersand and equals. encodeURI is for a complete address and leaves those separators untouched.

Is URL encoding the same as encryption?

No. Anyone can decode it instantly. It only makes text safe to put in a URL and gives no privacy or security.

Sources

More games

All games