Local-first tools. Your files and text stay in your browser.

data guide

URL encoding explained: reserved characters and query strings

Percent-encoding is not encryption. Learn reserved characters, UTF-8 bytes, encodeURIComponent and common double-encoding bugs.

Reviewed December 3, 2026 · TinkerFern editorial

A URL is a structured string, not a bag of characters. Characters such as ?, &, # and / have structural meaning, so a value that contains them must be encoded before it can travel inside a URL. Percent-encoding is the mechanism that makes this possible.

The unreserved set

RFC 3986 defines a small set of characters that may appear literally in any URL component:

A-Z a-z 0-9 - . _ ~

Everything else may need encoding. Reserved characters are reserved because they delimit parts of the URL:

  • General delimiters: : / ? # [ ] @
  • Sub-delimiters: ! $ & ' ( ) * + , ; =

A reserved character can still appear literally when its structural role is intended. The same character inside a data value must be encoded so it is not mistaken for a delimiter.

How percent-encoding works

Percent-encoding converts a character to its UTF-8 bytes, then writes each byte as % followed by two uppercase hexadecimal digits.

Character UTF-8 bytes Encoded
Space 20 %20
& 26 %26
/ 2F %2F
? 3F %3F
# 23 %23
é C3 A9 %C3%A9
😀 F0 9F 98 80 %F0%9F%98%80

This is why encoding is a byte operation, not a character substitution. A non-ASCII character expands to several percent triplets, and an already-encoded string can be encoded again if you are not careful.

Space: %20 or +?

In a URL path or query string, a space is normally %20. The + convention comes from application/x-www-form-urlencoded, the format used by classic HTML form submissions. In that format, + represents a space. The two are not interchangeable in every context.

Modern code should prefer %20 and use URLSearchParams for query strings. If you decode a + as a space in a path segment, you will corrupt legitimate plus signs.

JavaScript’s three different functions

JavaScript exposes several encoders with confusingly similar names:

  • encodeURIComponent() encodes a value for use inside one component. It leaves A-Z a-z 0-9 - _ . ! ~ * ' ( ) alone and encodes &, =, ?, / and #.
  • encodeURI() preserves URL structure, so it does not encode : / ? # & =. It is for encoding a complete URL, not a parameter value.
  • URLSearchParams handles query-string escaping and the +/space convention for you.

A common bug is using encodeURI() on a query value. The & inside the value remains literal, so the receiving server sees an extra parameter. Use encodeURIComponent() for individual values, or build the query with URLSearchParams.

const value = 'a&b=c';
const good = `/search?q=${encodeURIComponent(value)}`;
// /search?q=a%26b%3Dc

Double encoding

Encoding an already-encoded value turns %20 into %2520, because % itself becomes %25. The server then decodes once and receives the literal text %20 instead of a space.

Double encoding usually happens when both the client and an intermediate layer encode the same parameter, or when a redirect re-encodes a URL. Decode once at the boundary where the value stops being a URL component, and keep raw values in your application rather than pre-encoded strings.

Path segments are different

A slash inside a path is a separator. If a value such as a filename contains /, encode it as %2F before inserting it into a path. Do not rely on the server to guess. Some servers and proxies normalize encoded slashes differently, so avoid designing routes that depend on %2F being preserved.

For query parameters, the order and encoding of parameters can matter to signature schemes. If you are validating an HMAC-signed URL, canonicalize exactly as the specification requires; re-encoding a query string in a different order will break the signature even though the URL looks equivalent.

Unicode and normalization

Two visually identical strings can have different Unicode code points. For example, an accented character may be a single composed code point or a base letter plus a combining mark. Percent-encoding preserves the code points it was given, so normalization should happen before encoding if the value must match a canonical form.

Emoji and other characters outside the Basic Multilingual Plane use four UTF-8 bytes, which is why they produce four percent triplets. This is normal and not a sign of corruption.

Debugging checklist

  • Decode the value once and inspect the raw bytes, not the rendered text.
  • Check whether the parameter is in a path, query or fragment.
  • Confirm whether + is meant as a space or a literal plus.
  • Look for %25 where you expected %.
  • Verify that the server and client agree on the expected encoding.
  • Do not put secrets in a URL; they end up in logs, referrers and browser history.

The URL encoder and decoder converts between raw text and percent-encoded form locally. For binary payloads that need to travel in text, the Base64 tool is the right encoding, not percent-encoding. When a URL appears inside a JSON payload, format the payload with the JSON formatter before editing it.

Further reading: RFC 3986 for URI syntax, the WHATWG URL standard, and MDN’s documentation for encodeURIComponent and URLSearchParams.

Tools mentioned in this guide

Apply the advice with a tool that runs locally.

Continue with a related explainer from the same topic.

All guides →

← All guides · RSS feed

Privacy and cookie settings

This build loads no advertising scripts and no analytics vendor. If analytics is enabled by the owner, it sends only allowlisted event names and tool IDs, never your text, files or generated output.

Analytics
Disabled in this build
Advertising
Disabled in this build
Local storage
Theme, favorite tool IDs, recent tool IDs