Encoding & Decoding Guide
Master Base64, URL, HTML encoding and decoding with practical examples.
Encoding converts data from one representation to another for safe storage or transmission. Developers work with several encoding types daily — knowing when to use each prevents security vulnerabilities and data corruption.
Base64 Encoding
Converts binary data into printable ASCII using 64 characters. Used in email attachments, data URIs, JWT tokens, and Basic Auth headers.
- Output is ~33% larger than input (3 bytes → 4 characters)
- Ends with 1–2
=padding characters - NOT encryption — trivially reversible
btoa("Hello World") // → "SGVsbG8gV29ybGQ="
atob("SGVsbG8gV29ybGQ=") // → "Hello World" URL Encoding
Replaces unsafe URL characters with % + hex code. Spaces → %20, special chars like &, =, ? are encoded to prevent parsing ambiguity.
encodeURIComponent("Hello World!") // → "Hello%20World%21"
// Use encodeURIComponent for query param values
// Use encodeURI only for complete URLs HTML Entity Encoding
Prevents XSS by escaping HTML special characters:
&→&<→<>→>"→"
Frequently Asked Questions
Is Base64 safe for passwords?
No. Use bcrypt or Argon2 for passwords, AES for sensitive data. Base64 is not encryption.
When to use URL-safe Base64?
When the value appears in URLs or HTTP headers — JWT tokens use URL-safe Base64 (base64url) by spec.
What encoding should I always use for web?
Always UTF-8. It represents all Unicode characters and is backward-compatible with ASCII.
Related Tools
JSON Formatter
Beautify and format JSON with syntax highlighting and validation.
JSON Validator
Validate JSON syntax and structure instantly with detailed error messages.
JSON Minifier
Minify and compress JSON by removing all whitespace and formatting.
JSON to CSV
Convert JSON arrays and objects to CSV format for spreadsheets.
JSON to XML
Convert JSON data to well-formed XML format instantly.
JSON Diff
Compare two JSON objects and highlight the differences between them.