Complete Guide to URL Encoding for Developers

URL encoding converts special characters into a format that can be safely transmitted in web addresses. Here's what developers need to know.

What URL encoding is and why it exists

URLs can only contain a limited set of characters defined by the RFC 3986 standard. Characters outside this set — spaces, ampersands, brackets, accented letters, and others — must be encoded as a percent sign followed by the character’s hexadecimal ASCII code.

A space becomes %20, an ampersand becomes %26, a forward slash becomes %2F. This encoding ensures that URLs can be transmitted reliably across any system without ambiguity about where one part of the URL ends and another begins.

Use URL Encode / Decode to encode or decode URL components instantly.

The difference between encoding a full URL and a component

One of the most common URL encoding mistakes is encoding a full URL when you should be encoding a component, or vice versa.

Component encoding (encodeURIComponent in JavaScript) encodes everything except unreserved characters: letters, digits, -, _, ., and ~. It encodes /, ?, &, =, and # — characters that have structural meaning in a URL.

Full URL encoding (encodeURI in JavaScript) leaves the structural characters intact and only encodes characters that can’t appear in a URL at all. It preserves ?, &, =, /, # because they’re needed for the URL structure.

The practical rule: when you’re building a query parameter value that might contain special characters, use component encoding. When you’re encoding a complete URL to pass as a parameter to another URL, encode the whole thing as a component.

Common situations where encoding is required

Query string values — any user input or dynamic data in a query string must be encoded. A search term like C++ programming needs to become C%2B%2B%20programming before being appended to a URL.

Paths with special characters — file names or category names with spaces, slashes, or special characters in URL paths need encoding. A document named Q3 Report (Final).pdf becomes Q3%20Report%20%28Final%29.pdf.

Redirects and callback URLs — when passing a URL as a parameter value to another URL (OAuth redirect URIs are a common example), the entire inner URL must be component-encoded.

Form submissions — HTML forms with method="GET" URL-encode the form data automatically before appending it to the URL. Understanding this helps when debugging form behavior or building APIs that accept GET parameters.

Decoding: when you receive encoded data

URL decoding is the reverse process: converting percent-encoded sequences back to their original characters. This is necessary when:

  • Reading query parameters from inbound requests
  • Parsing log files that contain encoded URLs
  • Displaying user-facing URLs that were stored encoded
  • Debugging encoded values in API requests

Double-encoding is a common bug: a value that’s already encoded gets encoded again, so %20 becomes %2520. This produces incorrect decoded values. Always check whether data is already encoded before encoding it again.

URL encoding vs. Base64 encoding

URL encoding and Base64 encoding both convert data into a safe format for transmission, but they solve different problems.

URL encoding makes a string safe for use in a URL. The output is still human-readable text, just with some characters replaced by percent sequences. It’s designed for small strings — query parameters, path segments.

Base64 encoding converts binary data (images, files, arbitrary bytes) into ASCII text. The output is not human-readable. It’s used when you need to embed binary data in a text-based format like JSON, XML, or a URL parameter.

If you’re encoding a string to put in a URL, use URL encoding. If you’re encoding binary data or a long string to embed in another format, use Base64 Encode / Decode.

Practical debugging with encode/decode tools

When you receive a URL that looks broken or contains unexpected characters, pasting the relevant portion into a decoder immediately shows what the original value was. This is useful when:

  • An API is returning 400 errors on requests with special characters in parameters
  • A redirect is landing on the wrong page because the URL was double-encoded
  • Log entries show garbled values in query strings
  • You need to manually construct a URL with parameters containing special characters

Decode first to understand what you have, then re-encode correctly if needed. The URL Encode / Decode tool handles both directions instantly.

When to use JSON Formatter alongside URL tools

API endpoints that accept JSON in query parameters (unusual but it happens) produce particularly messy URLs. The JSON gets URL-encoded, resulting in a long string of percent sequences. Decode it first to get the raw JSON, then format it to make it readable.

Use JSON Formatter after decoding to inspect JSON payloads embedded in URLs.


✨ Missing something?
Can't find the tool you need?
Request it — we build new tools based on what people ask for.
Request a tool