hashids

Small PHP library to generate short, reversible YouTube-like IDs from numbers.

Library
Composer
v5.0.2
5,432stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
50/100Fair
Development Activity12
Maintenance20
Community68
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
84/100Excellent
Architecture82
Code Quality84
Innovation80
Learning Curve90

Hashids is a small PHP library that generates short, unique, non-sequential IDs from numbers - the kind of opaque identifiers you see in YouTube or Bitly URLs. You use it when you don’t want to expose raw, incrementing database IDs to users, because those leak record counts and are easy to enumerate.

The generated hashes are fully reversible: encode one or more integers into a string, then decode that string back into the original numbers. You can customize the alphabet, minimum length, and a salt so your IDs are unique to your application.

What You Get

  • A single Hashids class with encode() and decode() methods
  • Reversible mapping between integers and short opaque strings
  • Customizable salt so IDs are unique to your application
  • Configurable minimum hash length and custom alphabet
  • Support for encoding multiple numbers into one hash and hex encoding

Common Use Cases

  • Hiding sequential database primary keys in public URLs
  • Generating short, shareable IDs for links and resources
  • Encoding multiple numeric values into a single token
  • Producing non-guessable identifiers without a lookup table

Under The Hood

Architecture - The library is essentially one class, Hashids\Hashids (src/Hashids.php), implementing HashidsInterface; it shuffles the alphabet with the configured salt and performs base conversion to encode integers, with a pluggable Math abstraction (src/Math) that uses GMP or BCMath for large-number arithmetic when available. Tech Stack - Pure PHP with an optional dependency on the GMP or BCMath extension for big integers, tested via PHPUnit and GitHub Actions. Code Quality - The codebase is tiny, well-covered by a PHPUnit suite, and isolates platform-specific big-integer math behind a small interface, keeping the core algorithm readable. API Design - The public surface is just new Hashids(salt, minLength, alphabet) plus encode/decode (and hex variants), which makes it approachable in seconds while the constructor options cover the realistic customization needs.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search