Understanding the URL encoder and decoder — concept and principle
URLs may contain only a limited set of ASCII characters, and some of those, such as ?, & and =, have structural meaning. Percent-encoding replaces any other character, or a reserved one used as plain data, with % followed by two hexadecimal digits for each byte. This tool encodes a query value or a whole URL, or decodes percent-encoded text back to readable form, using UTF-8 for non-ASCII characters such as Korean.
How it is calculated
- Encode component (encodeURIComponent): every character except A–Z, a–z, 0–9 and - _ . ! ~ * ' ( ) is converted to UTF-8 bytes and each byte is written as %XX.
- Encode full URL (encodeURI): the same, but URL structure characters such as : / ? # & = + ; , @ $ are left unchanged.
- Decode (decodeURIComponent): first turns + into a space (the HTML form convention), then converts each %XX back to a byte and reads the bytes as UTF-8.
The principle
RFC 3986 divides characters into unreserved ones, which never need encoding, and reserved ones, which separate URL parts: ? starts the query, & separates parameters, = joins a name and value. If a value itself contains & or =, it must be encoded, otherwise the server will split it in the wrong place. Any byte can be written as % plus its two hex digits, and UTF-8 turns each non-ASCII character into a sequence of bytes, so any text in any language fits into a URL.
Worked example
- Input: name=홍길동&city=Seoul Korea, mode Encode component.
- "name" stays as is; = becomes %3D and & becomes %26.
- 홍 is UTF-8 ED 99 8D → %ED%99%8D; 길 → %EA%B8%B8; 동 → %EB%8F%99.
- The space becomes %20.
- Result: name%3D%ED%99%8D%EA%B8%B8%EB%8F%99%26city%3DSeoul%20Korea.
Because the whole string was treated as one value, its = and & were encoded too. To build a query, encode only each value: name= + encoded 홍길동.
How to read the result
Each Korean syllable becomes three %XX groups, so encoded Korean text is about nine times longer than the original character count. If decoding shows "invalid input", the text has a broken sequence such as a lone % or incomplete UTF-8 bytes.
Common mistakes
- Encoding a full URL with the component mode, which breaks :// and /.
- Encoding twice, turning % into %25 (for example %2520).
- Assuming + always means a space; it does only in form-encoded query strings.
Frequently asked questions
Should a space be %20 or +?
%20 is correct everywhere in a URL. + means a space only in application/x-www-form-urlencoded data such as HTML form submissions.
Why do some sites show Korean in the address bar?
Browsers display decoded text for readability, but they send the percent-encoded UTF-8 form to the server.
Are uppercase and lowercase hex digits different?
No. %3d and %3D are equivalent, though RFC 3986 recommends uppercase.
Sources: IETF RFC 3986, Uniform Resource Identifier (URI): Generic Syntax · ECMA-262, ECMAScript Language Specification (encodeURIComponent, encodeURI, decodeURIComponent) · WHATWG URL Standard