Encode numbers or text strings into Base62 format. Safe browser converter for URL shorteners.
Base62 encoding is a positional numeral system that utilizes a character set of 62 unique symbols: digits 0-9, uppercase letters A-Z, and lowercase letters a-z. Unlike Base64, which includes non-alphanumeric characters like '+' and '/', Base62 is strictly alphanumeric. This makes it the gold standard for generating URL-safe identifiers and human-readable short codes that do not require percent-encoding when transmitted via HTTP headers or URLs.
At its core, Base62 operates through a process of repeated division and remainder mapping. To encode a decimal integer, the system divides the number by 62 and uses the remainder as an index to select a character from the predefined alphabet string 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz. This process continues until the quotient reaches zero. The resulting sequence of characters, read in reverse order of their generation, constitutes the Base62 representation. Because it avoids special characters, it ensures maximum compatibility across all database systems, file systems, and web browsers without risking syntax errors or injection vulnerabilities.
The primary advantage of Base62 over standard Base10 (decimal) or Base16 (hexadecimal) is information density. A Base62 string can represent a significantly larger numerical value in a much shorter character length. For example, a 6-character Base62 string can represent over 56.8 billion unique IDs (62^6), whereas a 6-character decimal string can only represent one million.
Key technical features include:
encodeURIComponent().To implement a Base62 encoder, a developer must first define the alphabet. While the standard is 0-9, A-Z, a-z, some implementations shuffle this alphabet to create a basic form of obfuscation, preventing users from easily guessing the next ID in a sequence.
Consider the following JavaScript implementation for a Base62 encoder:
function encodeBase62(num) { const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; let result = ''; if (num === 0) return alphabet[0]; while (num > 0) { result = alphabet[num % 62] + result; num = Math.floor(num / 62); } return result; }To decode the string back to an integer, the process is reversed. Each character's index in the alphabet is multiplied by 62 raised to the power of its position in the string, and the sum of these values yields the original decimal number. This symmetry is critical for systems that store IDs as integers in a database (for indexing efficiency) but expose them as strings to the end-user (for aesthetic and functional reasons).
It is vital to understand that Base62 is an encoding scheme, not an encryption method. Encoding transforms data into a different format for utility, whereas encryption hides data for security. Because Base62 is reversible, any user who knows the alphabet can decode a Base62 string back to its original integer. Therefore, you should never use Base62 to hide sensitive data like user passwords or private keys.
To enhance security and prevent ID enumeration attacks (where a competitor or malicious actor increments a URL ID to scrape your database), developers should implement the following strategies:
The Base62 Encoder is primarily designed for backend engineers, system architects, and full-stack developers who are building scalable web applications. It is particularly useful for those working with NoSQL databases, RESTful APIs, and microservices where efficient resource naming is paramount. Data analysts also benefit from Base62 when creating compact identifiers for large datasets that need to be shared across different platforms without corruption.
In the modern cloud ecosystem, where billions of requests are processed per second, reducing the byte-size of identifiers in URLs reduces the overall payload size of HTTP requests, leading to marginal but cumulative improvements in latency and bandwidth consumption. This makes Base62 an essential tool for optimizing the Critical Rendering Path and improving the overall user experience of high-traffic platforms.
Base64 includes two non-alphanumeric characters (+ and /) and uses padding (=), which can require URL encoding. Base62 uses only 0-9, a-z, and A-Z, making it natively URL-safe without any additional escaping.
No. Base62 is a reversible encoding format, not encryption. Anyone with the alphabet can decode the string. For sensitive data, use AES or RSA encryption.
Standard Base62 encoding handles non-negative integers. To handle negative numbers, you must store the sign separately or use a signed integer mapping technique before encoding.
The best way is to shuffle the character alphabet randomly or add a large secret offset to your integer before encoding it.
No, it actually decreases the string length compared to decimal. It represents the same numerical value using fewer characters by increasing the base from 10 to 62.
Base62 is not typically a built-in library in most languages, but because it relies on simple modular arithmetic, it can be implemented in any language including JavaScript, Python, Java, Go, and C#.