Developer Tools

What Is URL Encoding and Why Is It Used?

Learn what URL encoding is, why special characters need percent-encoding in URLs, and how it differs from Base64.

Brekzy Team Published September 7, 2026 Updated September 8, 2026

On this page
  1. What Is URL Encoding?
  2. Why Do URLs Need Encoding?
  3. Common URL Encoded Characters
  4. URL Encoding vs URL Structure
  5. URL Encoding Examples
  6. URL Encoding vs Base64
  7. How to Encode and Decode URLs

URLs can only safely contain a limited set of characters. URL encoding is the mechanism that lets everything else (spaces, punctuation, non-English text) travel inside a URL without breaking it.

What Is URL Encoding?

A URL is really just a piece of text with a strict structure, and certain characters in that text have special meaning: a ? marks the start of a query string, a / separates path segments, an & separates parameters, and so on. URL encoding replaces characters that either have special meaning or aren’t allowed in a URL with a safe, standardized substitute, so the data can be included without confusing the parts of the URL around it.

Why Do URLs Need Encoding?

Encoding matters most when a value inside a URL, like a search query typed by a user, might contain characters that clash with the URL’s own syntax. A few common cases:

  • Spaces: not allowed in a URL at all, and must be encoded.
  • Reserved characters: characters like ?, &, #, and / that already mean something in URL structure need encoding when they appear as literal data rather than structure.
  • Query parameters: values submitted through a form or search box often contain spaces, punctuation, or symbols that need encoding to stay inside their own parameter correctly.

For example, a space is commonly represented as:

%20

This is called percent-encoding: a % followed by two hexadecimal digits representing the character’s byte value.

Common URL Encoded Characters

Here are a few examples of how encodeURIComponent, the standard JavaScript URL-encoding function, handles common characters:

Character Encoded
Space %20
@ %40
& %26
? %3F

Not every character gets encoded, and exactly which ones do can depend on context. For instance, !, *, ', (, and ) are left unencoded by JavaScript’s encodeURIComponent, even though older standards classify some of them as reserved. Different tools, languages, and encoding functions can draw the line in slightly different places, so it’s worth checking the specific one you’re using rather than assuming a single universal rule.

URL Encoding vs URL Structure

It helps to separate two different ideas: the structure of a URL, and the encoding applied to the data inside it. A URL is made up of several components:

  • Protocol: e.g. https://
  • Domain: e.g. example.com
  • Path: e.g. /search
  • Query parameters: e.g. ?q=coffee+shops
  • Fragment: e.g. #results

URL encoding is applied to the values inside these components, particularly the path and query parameters, not to the structural characters that separate them. To break a real URL down into these pieces and inspect each one, the URL Parser does this automatically.

URL Encoding Examples

Say a user searches for coffee & tea shop? on a site that puts the query directly into the URL. Encoded for use as a query parameter, it becomes:

coffee%20%26%20tea%20shop%3F

Each space became %20, the & became %26 (so it isn’t mistaken for a parameter separator), and the ? became %3F. Without encoding, the & and ? in the raw text would be misread as URL structure instead of part of the search term.

URL Encoding vs Base64

These two solve different problems. URL encoding makes text safe to place inside a URL by escaping characters that clash with URL syntax. Base64 converts binary data into text using a completely different character set and process, with no connection to URL structure at all. This comes up, for example, when a URL parameter needs to carry a small piece of What Is JSON? data: the JSON is often Base64-encoded first, and the whole result is URL-encoded on top. See What Is Base64 Encoding? for how that first step works.

How to Encode and Decode URLs

To convert text to and from its encoded form without doing it by hand, use the URL Encoder & Decoder.

Try it yourself

URL Encoder & Decoder

Try our URL Encoder & Decoder →

Frequently Asked Questions

What is URL encoding?

URL encoding, also called percent-encoding, is a way of representing characters inside a URL that would otherwise be unsafe or have a conflicting special meaning, by replacing them with a % followed by a two-digit hexadecimal code.

Why are spaces encoded in URLs?

A raw space isn’t a valid character inside a URL. Encoding it as %20 lets the URL include spaced-out text, like a multi-word search term, without breaking.

What does %20 mean?

%20 is the percent-encoded representation of a space character.

Is URL encoding the same as Base64?

No. They’re different techniques for different purposes: URL encoding escapes characters that conflict with URL syntax, while Base64 converts binary data into text using an entirely different character set.

Should every character in a URL be encoded?

No. Only characters that are unsafe or have special meaning in the given context need encoding. Encoding everything, including already-safe characters like letters and digits, is unnecessary and makes URLs harder to read.

What is percent encoding?

Percent encoding is the formal name for the mechanism URL encoding uses: representing a character as a % sign followed by its byte value written in hexadecimal.

Explore More

Find the right tool, or keep reading Brekzy's other guides.