URL Encode / Decode

Encode or decode text for use in a URL, using standard percent-encoding.

Reset

Understanding URL encoding

A web address can only hold a limited set of characters. Letters, digits and a handful of punctuation marks travel unchanged, but a space, an ampersand, a question mark or a letter from another alphabet cannot appear raw in a URL — each of those characters already means something to a browser, or simply has no place in an address. A space inside a link would break it in two; an ampersand inside a search term would be read as the start of a new parameter.

Formula and method

UTF-8 text → percent-encoded text

Encoding: Decoding: Percent-encoded text → UTF-8 text Text — the characters to convert, in either direction. Encoding starts from readable text; decoding starts from text that already holds percent codes. Action — Encode or Decode. Encoding replaces characters outside the unreserved set with percent codes; decoding reverses the process. Unreserved characters — letters, digits and the marks - _ . ~, which travel unchanged and are never encoded. Percent code — a percent sign followed by two hexadecimal digits giving the character's code. A space is %20 because 20 in hexadecimal is 32 in decimal, the space's code. UTF-8 — the character encoding used for non-English letters. A letter such as é is stored as two bytes, C3 and A9, so it encodes as %C3%A9. Plus sign — treated literally rather than as a space, so a + in the input encodes as %2B and is not mistaken for a space on the way back. Why spaces need encoding. A URL cannot hold a raw space, because the space would end the address where it appears. Why an ampersand is encoded inside a value. The & character separates parameters in a query string, so an ampersand that is part of a value — as in "fish & chips" — must be encoded as %26 or it will be read as a separator. Why decoding is exact. Each code names exactly one byte, and UTF-8 groups those bytes back into the original characters, so nothing is lost in the round trip: encoding then decoding returns the text that went in.

Worked example

Example 1 — Encode "Hello world" (the live-page example) The text "Hello world" with the action Encode. The space is not allowed raw in a URL, so it is replaced by its code, %20. Every other character is a letter, so it travels unchanged. Result: Hello%20world (converted text) The live page carries this example, and the conversion above gives the same encoded text.