Hash Lab

Non-cryptographic

FNV-1a

The Fowler-Noll-Vo hash family (1991) is a tiny multiply-XOR mixer that fits in a few lines of code. FNV-1a, the “XOR-then-multiply” variant, distributes input bits noticeably better than the original FNV-1 and is the de facto choice for the family today.

The whole algorithm, in one fragment

hash = FNV_OFFSET_BASIS
for each byte b in input:
    hash = hash XOR b
    hash = hash * FNV_PRIME    # modulo 2^n, where n = 32 or 64

At a glance

Output32 or 64 bits (1024-bit variants exist but rarely used)
Internal state1 integer of output size
Throughput~1–3 GiB/s (single-byte loops; can be SIMD-vectorized)
Year1991 (original); FNV-1a variant ~1996
StatusNon-cryptographic; trivially collidable but fine for hash tables

Constants

VariantOffset basisPrime
FNV-1a 320x811c9dc50x01000193
FNV-1a 640xcbf29ce4842223250x00000100000001b3

Where it shows up

Limitations

For hot paths with adversarial inputs, prefer SipHash. For sheer throughput, prefer xxHash3.

References

Test Your Knowledge

Quick MCQ check on this algorithm

Start Quiz →

AI Summary

Summarize this page in your favorite LLM