What is Short UUID?
Short UUID is a technique to compress standard 128-bit UUIDs into shorter, URL-friendly strings. It typically involves:
- Base conversion: Converting the UUID from base-16 (hex) to a higher base (usually base-58 or base-62)
- Character set selection: Using URL-safe character sets with no ambiguous characters
- Lossless compression: Preserving all information from the original UUID
Example transformation:
- Standard UUID:
f47ac10b-58cc-4372-a567-0e02b2c3d479
- Short UUID (base-58):
2kLrTdCQVWFjc7dYXzzB5A
How Short UUID works
- Remove hyphens from the standard UUID
- Convert the resulting 32-character hex string to a decimal number
- Convert the decimal number to a higher base (58, 62, 64, etc.)
- Pad the result if necessary to ensure consistent length
Common encoding alphabets include:
- Base-58: Alphanumeric without ambiguous characters (0, O, I, l)
- Base-62: All alphanumeric characters (a-z, A-Z, 0-9)
- Base-64: Alphanumeric plus two special characters (often + and /)
Advantages & Considerations
Advantages | Considerations |
---|---|
|
|
Length Comparison
Format | Length | Character Set | Example |
---|---|---|---|
Standard UUID | 36 chars | Hex + hyphens | f47ac10b-58cc-4372-a567-0e02b2c3d479 |
Hex (no hyphens) | 32 chars | 0-9, a-f | f47ac10b58cc4372a5670e02b2c3d479 |
Base-58 | 22 chars | No 0, O, I, l | 2kLrTdCQVWFjc7dYXzzB5A |
Base-62 | ~22 chars | Alphanumeric | 3pqLYdcw9TGKxNVgeO0gOd |
Base-64 | ~22 chars | Alphanumeric + symbols | 9HrBC1jMQ3KlZw4CssPUeQ== |
Common Base-58 Alphabet
The Base-58 alphabet is designed to be visually unambiguous when displayed in both fixed-width and proportional fonts:
Character set | Content |
---|---|
Numbers | 1-9 (excluding 0) |
Uppercase letters | A-Z (excluding I, O) |
Lowercase letters | a-z (excluding l) |
Characters: 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
Common Use Cases
- URL shortening: More compact URL parameters
- Public-facing IDs: User or content identifiers
- QR code optimization: Fewer characters = simpler codes
- Mobile applications: Less data transmission
- API design: Cleaner, more compact resource identifiers
- Social sharing: More user-friendly links
Frequently Asked Questions
Are Short UUIDs as unique as standard UUIDs?
Yes. Short UUIDs are just a different representation of the same 128-bit value. The conversion is lossless, preserving all the uniqueness properties of standard UUIDs.
Can I convert between standard and Short UUID formats?
Yes. The conversion is bidirectional - you can encode a standard UUID to Short UUID and decode it back to exactly the same standard UUID.
Which base encoding is most recommended?
Base-58 is often preferred because it avoids ambiguous characters (0/O and l/I) while staying URL-safe without requiring URL encoding.
How much shorter are Short UUIDs?
Standard UUIDs are 36 characters (with hyphens). Short UUIDs are typically 22 characters when using base-58/62/64 encoding, a reduction of about 40%.
Should I store Short UUIDs in my database?
It's generally recommended to store the standard UUID format in databases and convert to Short UUID only when displaying to users or in URLs. This provides better compatibility with database UUID types.