How to use the DJB2 hash calculator
- Type or paste the string in Text.
- Leave Input is on Text (UTF-8), or pick Hex bytes or Base64 bytes for raw data.
- Choose the Variant: hash × 33 + c (classic djb2) or hash × 33 ^ c (djb2a).
- Read DJB2 (hex), the unsigned Decimal value and the Input size.
What it does and when to use it
Daniel J. Bernstein posted this hash to the comp.lang.c newsgroup, and it became one of the most copied snippets in C. You still find it in game engines, embedded firmware, interpreters and coding exercises. Use this page when you need to reproduce a value your code stores, build a test case, or understand why two keys landed in the same bucket.
To compare djb2 with sdbm, FNV, MurmurHash3 and others in one table, use the simple string hash table. For a stronger fast hash, try the FNV hash calculator. To check data for transmission errors, use a real checksum such as CRC-32.
How it works
The tool encodes text as UTF-8 and then processes it one byte at a time:
- djb2:
hash = hash × 33 + byte - djb2a:
hash = (hash × 33) XOR byte
The starting value is 5381. After every step the result is reduced to an unsigned 32-bit number, so it always fits in 8 hex digits. The code runs in your browser.
Worked examples
One letter. For a (byte 97): 5381 × 33 + 97 = 177670. The tool shows DJB2 (hex): 0002b606 and Decimal: 177670.
Two letters. For ab, the next step is 177670 × 33 + 98 = 5863208, shown as 00597728.
The XOR variant. With djb2a, a gives (5381 × 33) XOR 97 = 177573 XOR 97 = 177604. Then 177604 × 33 = 5860932, and 5860932 XOR 98 = 5860902. So ab returns Decimal: 5860902. The two variants already disagree after the first byte, which is why you must know which one a program uses.
Empty input. No bytes means no steps, so the result is the seed, 5381.
Limits and tips
- Short strings give small numbers: anything under 4 bytes cannot use the full 32-bit range.
- Swapping two letters changes the result, because each byte is multiplied by a different power of 33, but collisions are still easy to find on purpose.
- When you use the hash to pick a bucket, take the decimal value modulo the table size.
- djb2 is a lookup hash, not an error-detection code; the note under the result points to CRC-32 for that.
Frequently asked questions
Why 5381 and 33?
My C program gives a different number for long strings. Why?
Is djb2 good enough for a hash table?
Can I use djb2 to check passwords or file integrity?
Sources
- Hash functions (djb2 and sdbm) — Ozan Yigit, York University, accessed 2026-10-07
How do we know nothing is uploaded? Test it yourself on the privacy proof page.