Skip to main content
miji.be

Base62 Encoding

An encoding scheme that represents data using 62 alphanumeric characters (a-z, A-Z, 0-9). Widely used to generate short URL codes.

Nov 3, 2026 / About 1 min read

URL Shortening

Base62 encoding represents data using 26 lowercase letters (a-z), 26 uppercase letters (A-Z), and 10 digits (0-9), totaling 62 characters. It is used to generate short URL codes.

Why Base62 suits short URLs can be shown with numbers. A 6-character Base62 code can represent 62^6, roughly 56.8 billion unique patterns. With 7 characters, that jumps to about 3.5 trillion.

One implementation used by short URL services assigns a unique integer ID to each URL and converts that ID to Base62 to produce the short code. For example, with the character order 0-9, a-z, A-Z, ID 12345 converts to "3d7" (3 characters). Codes grow longer as IDs increase, but values up to roughly 56.8 billion still fit within 6 characters.

Base64 is a similar scheme, but it includes "+" and "/", which can be problematic in URLs. The alphanumeric characters used by Base62 are among the unreserved characters that RFC 3986 allows in URLs as-is, so no additional encoding is needed.

Implementing Base62 is a base-10 to base-62 conversion, achievable in a few lines of code in most languages. One caveat: converting sequential IDs directly to Base62 makes codes predictable, which is a security concern. Countermeasures include combining the ID with a hash function or generating random strings.

Was this article helpful?

Related Terms

Short URL

A condensed version of a long URL that redirects to the original destination. Short URLs are easier to share and track.

URL Encoding

URL encoding (percent-encoding) converts special characters into percent-encoded sequences (%XX) safe for use in URLs. Essential for handling spaces, Unicode characters, and reserved symbols in web addresses.

Percent-Encoding

A mechanism for encoding special characters in URLs by replacing them with a percent sign followed by hexadecimal digits.

Custom Alias

A custom alias is a user-defined short code that replaces the auto-generated random string in a short URL. It improves brand recognition, memorability, and click-through rates.

Slug

A URL-friendly string identifier derived from a title or name, used to create readable and SEO-friendly web addresses.

QR Code Encoding

The process of converting data into the pattern of modules that form a QR code.

Related Articles

How URL Shorteners Work - The Technical Side of Redirects

Discover the technical mechanics behind URL shortening: hash generation, database lookups, HTTP redirects, and more. Includes HTTP response examples and base-62 encoding calculations.

URL Shortener API Guide - Generating Short URLs Programmatically

A practical guide to using URL shortener APIs. Learn about request formats, response structures, authentication, and implementation patterns.

GitHub Short URLs - Shorten Long Issue, PR, and Blob URLs for Developer Workflows

Manage GitHub long Issue, PR, and blob URLs with short links. Streamline code reviews, documentation, and team communication with custom short URLs.

FAQ

What is the difference between Base62 and Base64?
Base64 uses 64 characters (alphanumerics plus "+" and "/"). Because "+" and "/" are reserved characters in URLs, they can be problematic there. Base62 uses only alphanumeric characters, so it can be embedded in URLs as-is.
How many characters is a typical Base62 short code?
It varies by service. Six characters yield about 56.8 billion patterns and seven about 3.5 trillion, so the length is chosen to match the number of links needed.
Is there a risk of short codes being predicted?
If sequential IDs are converted directly to Base62, the next code becomes predictable. Countermeasures include applying a hash function or generating random strings directly.

Put the terms to work

Shorten a URL for Free