What Is URL Encoding?
URL encoding (also called percent-encoding) is a mechanism for converting characters that are not safe to use in a URL into a format that can be transmitted safely over the internet. The URL specification (RFC 3986) defines a limited set of characters as "unreserved" β letters AβZ, digits 0β9, and the symbols -, _, ., and ~. Every other character must be percent-encoded before it can appear in a URL.
You've seen percent-encoding in action without knowing it. The %20 in a URL stands for a space character. The %40 stands for the @ symbol. When you paste a URL into a browser and press Enter, the browser decodes these sequences back into the original characters for display β but the encoded form is what travels across the network.
How Percent Encoding Works
The mechanism is straightforward: take the character, find its UTF-8 byte value(s), write each byte as a two-digit uppercase hexadecimal number prefixed with a percent sign.
For single-byte ASCII characters:
- Space (ASCII 32) β
%20 - Exclamation mark ! (ASCII 33) β
%21 - Hash # (ASCII 35) β
%23 - Ampersand & (ASCII 38) β
%26 - Plus + (ASCII 43) β
%2B - Equals = (ASCII 61) β
%3D - Question mark ? (ASCII 63) β
%3F - At sign @ (ASCII 64) β
%40
For multi-byte UTF-8 characters (non-ASCII, like accented letters or emoji), each byte in the UTF-8 sequence gets its own percent prefix. The letter Γ© (UTF-8: 0xC3 0xA9) becomes %C3%A9. The euro sign β¬ (UTF-8: 0xE2 0x82 0xAC) becomes %E2%82%AC.
When to Encode vs Decode
Encode when: you're building a URL that contains user-supplied input, special characters, or non-English text. This includes: constructing API request URLs with query parameters, embedding search terms in URLs, generating share links with dynamic content, or creating redirect URLs in code.
Decode when: you receive a percent-encoded URL and need to read it as a human, debug an API request, check what a redirect target actually says, or extract readable text from a logged URL. Analytics dashboards and server logs often show percent-encoded URLs β decoding them makes the data understandable.
Note: never double-encode a URL. If a string is already percent-encoded, encoding it again will turn the % signs into %25, producing malformed results. Always decode first if you're unsure of the input state.
Common URL Encoding Examples
Here are the most frequently encoded characters and their encoded equivalents:
- Space β
%20(or+in form data/query strings) - & β
%26(critical in query strings β raw & is a parameter separator) - = β
%3D(the key=value separator in query strings) - + β
%2B(+ has a special meaning as "space" in form encoding) - / β
%2F(slashes separate URL path segments) - ? β
%3F(the query string delimiter) - # β
%23(the fragment identifier) - @ β
%40(used in mailto: URLs and older URL auth syntax) - " β
%22(quotes must be encoded in HTML href attributes)
URL Encoding in Query Strings
Query strings (the part of a URL after the ?) are the most common context for URL encoding errors. A query string like ?q=hello world&lang=en is invalid because the space and literal & need encoding. The correct form is ?q=hello%20world&lang=en.
There's also a subtle distinction between encodeURIComponent and encodeURI in JavaScript:
encodeURIencodes a full URL β it leaves characters like/,?,#, and&intact because they're structural parts of the URL.encodeURIComponentencodes a URL component (like a query parameter value) β it encodes/,?,#, and&because those characters should not be interpreted as URL structure inside a parameter value.
For most practical tasks (encoding a search query or a parameter value), encodeURIComponent behavior is what you want. Online URL encoders default to this behavior.
How to Encode or Decode a URL Online
A browser-based URL encoder/decoder converts any string instantly:
- To encode: paste your raw text (containing spaces, special characters, or non-ASCII) into the input, select Encode, and get the percent-encoded output.
- To decode: paste a percent-encoded URL or string, select Decode, and read the human-readable result.
Combine URL encoding with other data tools for common workflows: format JSON with the JSON formatter before encoding it as a query parameter, or use the extra spaces remover to clean up strings before encoding them into URLs.