T
Free Tools
All ToolsBlogDeveloperCalculatorsDocumentsAboutFAQContact
Back to Blog

Developer Guide

URL Encoding Explained — Why Special Characters Break Your Links

Learn why URLs need encoding, the percent-encoding standard, and how to handle special characters safely.

By Zohaib2026-05-129 min read

What is URL Encoding?

URL encoding (also called percent encoding) is a method of encoding special characters in URLs so they can be safely transmitted over the internet. URLs can only contain certain characters: letters (A-Z, a-z), digits (0-9), hyphens (-), periods (.), underscores (_), and tildes (~). Any other character, including spaces, special symbols, and accented letters, must be encoded before inclusion in a URL.

When you encode a character, you replace it with a percent sign (%) followed by its hexadecimal ASCII value. For example, a space is encoded as %20, a question mark is %3F, and an ampersand is %26.

Why Special Characters Break URLs

Reserved Characters with Special Meaning

Some characters have special meaning in URLs. For example, the question mark (?) indicates the start of query parameters, the ampersand (&) separates multiple parameters, and the hash (#) indicates a fragment identifier.

https://example.com/search?q=hello world&sort=date#results

In this URL, the ? means "parameters start here", & means "another parameter", and # means "fragment starts here". If you want to include these characters literally in a parameter value, they must be encoded.

Problem: If you want to search for "hello & goodbye", you cannot write:

https://example.com/search?q=hello & goodbye

The & character would be interpreted as a parameter separator, breaking the URL.

Solution: Encode the ampersand:

https://example.com/search?q=hello%20%26%20goodbye

Spaces and Whitespace

URLs cannot contain spaces. Any space must be encoded as %20 (or sometimes as a plus sign + in query strings, though %20 is preferred).

Accented Characters

Characters with accents (é, ñ, ü) and non-ASCII characters must be encoded to UTF-8 bytes and then percent-encoded. For example, "café" becomes "caf%C3%A9".

The Percent-Encoding Standard

How Encoding Works

To encode a character, follow these steps:

1. Convert the character to its UTF-8 byte representation

2. Convert each byte to hexadecimal

3. Prefix each hex value with %

Example: Encoding "?"

The question mark (?) has ASCII value 63

In hexadecimal: 63 = 3F

Encoded: %3F

Common Encoded Characters

Character ASCII Value Encoded
Space 32 %20
" 34 %22
% 37 %25
& 38 %26
+ 43 %2B
/ 47 %2F
? 63 %3F
# 35 %23

Real-World Use Cases

API Query Parameters

When building API requests with query parameters, special characters must be encoded:

// User search with name containing spaces and special characters
https://api.example.com/search?name=John%20O%27Brien&email=john%40example.com

OAuth Redirect URLs

When implementing OAuth, the redirect_uri parameter must be URL-encoded:

https://oauth.example.com/authorize?client_id=123&redirect_uri=https%3A%2F%2Fmyapp.com%2Fcallback

Form Submission Data

When submitting HTML forms, browsers automatically encode the data. If you manually construct form data, you must encode special characters:

POST /contact
message=Hello%20World%21%20This%20is%20a%20test%3F

URL Slugs with Special Characters

If you have a page titled "C++ Programming Guide", the URL needs encoding:

https://example.com/blog/c%2B%2B-programming-guide

Encoding vs Double Encoding

Single Encoding: Encode special characters once.

hello world → hello%20world

Double Encoding: Encode already-encoded data.

hello world → hello%20world → hello%2520world

Double encoding is usually a mistake and causes URLs to break. Always encode data at the source, not multiple times.

Using the URL Encoder Tool

Manually calculating percent encoding is tedious and error-prone. Use the URL Encoder tool to instantly encode or decode URLs. Paste your text and select encode, or paste an encoded URL and select decode. The tool handles edge cases, UTF-8 characters, and respects URL structure automatically.

Best Practices

1. Let your framework handle encoding: Modern frameworks (React, Vue, Express, Django) have built-in URL encoding. Use framework methods instead of manual encoding.

2. Use UTF-8 encoding: Always use UTF-8 for URL encoding, not ASCII or other encodings.

3. Test with special characters: When building URLs programmatically, test with special characters, accents, and international characters.

Conclusion

URL encoding is fundamental to web development. Special characters cannot be used directly in URLs because they have reserved meanings or are unsafe for transmission. By understanding the percent-encoding standard and using URL encoding tools, you avoid bugs in API calls, OAuth integrations, form submissions, and dynamic URL generation. Remember: when in doubt, encode it.


About the Author

Written by Zohaib, a web developer from Pakistan. Zohaib created Online Free Tools to help developers, students, and creators save time by providing quick access to essential utilities without installing software or creating accounts. When not coding, Zohaib writes technical guides to help others master web development concepts.

Published: May 12, 2026

Try related tools

URL Encoder

Open the tool and apply this article's ideas immediately.

Open tool

Related posts

More articles you may like

Developer Guide

What is JSON? A Beginner's Complete Guide

Learn what JSON is, how it works, common syntax rules, and why it is the standard for modern APIs and data exchange.

Read article
Developer Guide

What is a JWT Token? Plain English Explanation

Understand JWT tokens, how they work, why they are better than sessions, and how to use them securely in your applications.

Read article
Developer Guide

Base64 Encoding Explained — How It Works and When to Use It

Learn what Base64 encoding is, how the algorithm works, and practical use cases in APIs, emails, and web development.

Read article

About

Free Online Tools offers a curated collection of 30+ browser-based utilities plus a blog with practical guides, quick tips, and tool tutorials.

Tools

  • All Tools
  • Blog
  • Developer Tools
  • Document Tools
  • Calculators

Legal

  • Privacy Policy
  • Terms of Service
  • FAQ
  • Contact

Creator

Built by Zohaib, a web developer from Pakistan.

•GitHub•Sitemap

© 2026 Free Online Tools by Zohaib Hassan. All rights reserved.

Online Free Tools - Created with ❤️ for developers