url-encode url-decode percent-encoding developer-tools rfc3986

URL Encode Online Free: The Ultimate Guide to Percent-Encoding

Encode and decode URLs online for free. Learn about RFC 3986 percent-encoding, reserved characters, and common issues in URL structure.

2026-04-16 Use This Tool

URL Encode Online Free: The Ultimate Guide to Percent-Encoding

URL encoding, also known as Percent-encoding, is a mechanism for encoding information in a Uniform Resource Identifier (URI). While it might seem like a simple technical detail, it's a fundamental part of how the web works, ensuring that data is transmitted correctly between browsers and servers.

In this guide, we'll dive deep into why URL encoding is necessary, how it works, and provide a convenient online tool to handle it for you.

Why Do We Need URL Encoding?

URLs (Uniform Resource Locators) have a limited character set defined by RFC 3986. They can only contain certain characters. If you need to include characters that are not part of this set—such as spaces, non-ASCII characters (like those in Chinese or Arabic), or characters with special meaning in a URL (like & or =)—you must encode them.

Reserved vs. Unreserved Characters

According to the specification, characters are divided into two categories:

  1. Unreserved Characters: These can be used in a URL without being encoded. They include:

    • Uppercase and lowercase letters (A-Z, a-z)
    • Decimal digits (0-9)
    • Hyphen (-), underscore (_), period (.), and tilde (~)
  2. Reserved Characters: These have special meaning in a URL (e.g., they are used as delimiters like /, ?, #, [, ], @, !, $, &, ', (, ), *, +, ,, ;, =). If these characters are part of the data being sent (like a search query) and not acting as delimiters, they must be encoded.

How Percent-Encoding Works

Percent-encoding replaces a reserved character with a % followed by its two-digit hexadecimal representation of its ASCII value.

For example:

  • A space becomes %20 (ASCII value 32, hex 20).
  • An exclamation mark (!) becomes %21 (ASCII value 33, hex 21).
  • An ampersand (&) becomes %26 (ASCII value 38, hex 26).

Common Encoded Characters Table

Character Encoded Value Description
Space %20 or + Depends on the part of the URL
! %21 Exclamation mark
# %23 Hash (fragment identifier)
$ %24 Dollar sign
& %26 Ampersand (query delimiter)
' %27 Single quote
( %28 Left parenthesis
) %29 Right parenthesis
* %2A Asterisk
+ %2B Plus sign
, %2C Comma
/ %2F Forward slash (path delimiter)
: %3A Colon
; %3B Semicolon
= %3D Equals sign (query param)
? %3F Question mark (query start)
@ %40 At sign

Handling Spaces: %20 vs. +

You may have noticed that sometimes spaces are encoded as %20 and other times as +.

  • %20 is the standard encoding for a space in any part of the URI.
  • + is specifically used for spaces within the query string part of a URL (after the ?). This comes from the legacy application/x-www-form-urlencoded media type used by HTML forms.

Modern tools and libraries usually handle this automatically, but it's a common point of confusion for developers.

URL Encoding in Programming

Most programming languages provide built-in functions for URL encoding and decoding.

JavaScript

// Encoding a URI component
const query = "hello world & friends";
const encoded = encodeURIComponent(query);
console.log(encoded); // Output: hello%20world%20%26%20friends

// Decoding
const decoded = decodeURIComponent(encoded);
console.log(decoded); // Output: hello world & friends

Python

import urllib.parse

query = "hello world & friends"
encoded = urllib.parse.quote(query)
print(encoded) # Output: hello%20world%20%26%20friends

decoded = urllib.parse.unquote(encoded)
print(decoded) # Output: hello world & friends

PHP

<?php
$query = "hello world & friends";
$encoded = urlencode($query);
echo $encoded; // Output: hello+world+%26+friends

$decoded = urldecode($encoded);
echo $decoded; // Output: hello world & friends
?>

Frequently Asked Questions (FAQ)

1. Should I encode the entire URL or just parts of it?

You should usually only encode the values of your query parameters or specific segments of the path. Encoding the entire URL (including the http://, :, and / separators) will make it invalid as a URI. Use encodeURIComponent() for values and encodeURI() for the whole URI (it will skip delimiters).

2. Is URL encoding the same as Base64 encoding?

No. URL encoding (Percent-encoding) is used to escape characters in a URL. Base64 is used to represent binary data as a string of 64 ASCII characters. They serve completely different purposes.

3. Why did I get a "Malformed URI" error?

This usually happens during decoding when the string contains a % character that is not followed by two valid hexadecimal digits. For example, index.php?name=100% would cause an error because the % at the end is not a valid start of an encoded sequence.

4. Does URL encoding support Unicode?

Yes. Modern URL encoding (UTF-8 based) handles Unicode by first converting the character to its UTF-8 byte sequence and then percent-encoding each byte. For example, the character (UTF-8: E6 B1 89) becomes %E6%B1%89.

Conclusion

URL encoding is a simple but vital tool for ensuring web data integrity. Whether you're building a web application, debugging API calls, or just curious about how the web works, understanding percent-encoding is essential.

Need to encode or decode a string quickly? Use our URL Encode/Decode Tool to get it done in seconds!