Urlpercent Encoding Calculator
Our encoding & hash tool computes urlpercent encoding accurately. Enter your inputs for detailed analysis and optimization tips.
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer
Formula
Encoded = %HH where HH is the hexadecimal byte value
Each character that needs encoding is converted to its UTF-8 byte representation. Each byte is then written as a percent sign followed by two hexadecimal digits. For example, space (byte 0x20) becomes %20, and multi-byte Unicode characters produce multiple %HH sequences.
Worked Examples
Example 1: Encoding a Search Query Parameter
Problem:Encode the search query "best cafรฉ in Sรฃo Paulo" for use as a URL parameter value.
Solution:Original: best cafรฉ in Sรฃo Paulo Space -> %20, รฉ -> %C3%A9, รฃ -> %C3%A3 encodeURIComponent result: best%20caf%C3%A9%20in%20S%C3%A3o%20Paulo Original bytes: 24 Encoded bytes: 42 Size increase: 75%
Result:Encoded: best%20caf%C3%A9%20in%20S%C3%A3o%20Paulo | 5 characters needed encoding
Example 2: Decoding a Complex URL Fragment
Problem:Decode: filter%3Dprice%26sort%3Dasc%26q%3Dhello%20world
Solution:Percent sequences: %3D -> = (equals sign) %26 -> & (ampersand) %20 -> (space) Decoded result: filter=price&sort=asc&q=hello world This reveals the original query string structure.
Result:Decoded: filter=price&sort=asc&q=hello world | 5 percent sequences resolved
Frequently Asked Questions
What is URL percent encoding and why is it necessary?
URL percent encoding, also known as URL encoding, is a mechanism for encoding characters that are not allowed in a Uniform Resource Identifier (URI) by replacing them with one or more percent signs followed by hexadecimal digits representing the character byte values. This encoding is necessary because URIs can only contain a limited subset of ASCII characters including letters, digits, and a few special characters like hyphens and underscores. Characters outside this safe set, such as spaces, non-ASCII characters, and reserved characters that have special meaning in URI syntax, must be encoded to be transmitted correctly. For example, a space character (ASCII 32, hex 20) becomes percent-20. Without percent encoding, a URL containing spaces or special characters would be ambiguous or malformed, causing web servers and browsers to misinterpret the intended resource path or query parameters.
What is the difference between encodeURI and encodeURIComponent?
These two JavaScript functions serve different encoding purposes and handle reserved characters differently. The encodeURI function is designed to encode a complete URI and therefore preserves characters that have special meaning in URI structure, including colons, forward slashes, question marks, hash signs, ampersands, and equals signs. This means encodeURI will not break a well-formed URL by encoding its structural delimiters. In contrast, encodeURIComponent is designed to encode a single component of a URI, such as a query parameter value, and will encode all special characters including those with structural meaning. For example, encoding the string "name=John&age=30" with encodeURI preserves the ampersand and equals signs, while encodeURIComponent converts them to percent-26 and percent-3D respectively. Using the wrong function can either break valid URLs or fail to properly encode parameter values.
Which characters are safe and do not need percent encoding?
The unreserved characters that never need percent encoding in any part of a URI are defined in RFC 3986 and include uppercase letters A through Z, lowercase letters a through z, digits 0 through 9, and four special characters: hyphen, period, underscore, and tilde. These 66 characters can appear anywhere in a URI without ambiguity. Additionally, reserved characters like colon, slash, question mark, hash, brackets, at sign, exclamation, dollar, ampersand, single quote, parentheses, asterisk, plus, comma, semicolon, and equals have specific syntactic roles in URIs and should only be encoded when they appear in positions where their reserved meaning could cause misinterpretation. All other characters, including spaces, non-ASCII characters, and control characters, must always be percent-encoded using their UTF-8 byte representation.
How does percent encoding handle Unicode and multi-byte characters?
Percent encoding handles Unicode characters by first converting them to their UTF-8 byte representation and then encoding each byte as a separate percent-encoded triplet. For example, the Euro sign has Unicode code point U+20AC which in UTF-8 is represented as three bytes: E2, 82, and AC. Therefore it is percent-encoded as percent-E2 percent-82 percent-AC. This means that a single Unicode character can produce anywhere from one to four percent-encoded triplets depending on its code point. ASCII characters (U+0000 to U+007F) produce one triplet. Characters in the range U+0080 to U+07FF produce two triplets. Characters from U+0800 to U+FFFF produce three triplets. And supplementary characters above U+FFFF, including many emoji, produce four triplets. This multi-byte encoding is why percent-encoded strings containing non-ASCII characters can be significantly longer than their original text.
What are common pitfalls and errors in URL encoding?
Several common mistakes occur when working with URL encoding that can cause bugs and security vulnerabilities. Double encoding is the most frequent error, where an already-encoded string is encoded again, turning percent-20 into percent-25-20, which decodes to the literal text percent-20 rather than a space. Inconsistent encoding occurs when some parts of a URL are encoded but others are not, or when different encoding functions are mixed inappropriately. Forgetting to encode user-supplied input in query parameters creates injection vulnerabilities where users can manipulate URL structure. Using plus signs for spaces is another source of confusion, as the plus-to-space convention only applies in HTML form submissions with the application/x-www-form-urlencoded content type, not in general URI encoding. Encoding path separators (forward slashes) when they should be preserved, or failing to encode them in parameter values where they should not be interpreted as path delimiters, are also common sources of broken URLs.
References
Background & Theory
History
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer ยท Editorial policy
Related Calculators
๐งฎBandwidth Time Transfer Calculator
Calculate bandwidth time transfer with inputs, formulas, and instant results.
๐งฎDownload Time Calculator
Calculate download time with inputs, formulas, and instant results.
๐งฎThroughput Efficiency Calculator
Calculate throughput efficiency with inputs, formulas, and instant results.
๐งฎBase64encode Decode Calculator
Calculate base64encode decode with inputs, formulas, and instant results.
๐งฎHash Checksum Calculator
Calculate hash checksum with inputs, formulas, and instant results.
๐งฎCron Expression Builder Calculator
Calculate cron expression builder with inputs, formulas, and instant results.