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

Quick quiz

Test yourself on fnv-1a

10 multiple-choice questions. Pick an answer for each, then submit to see explanations.

  1. Q1.What does FNV stand for?

  2. Q2.What year was FNV first published?

  3. Q3.FNV-1a differs from FNV-1 by:

  4. Q4.What is the FNV-1a 32-bit prime?

  5. Q5.FNV-1a's internal state size:

  6. Q6.Is FNV-1a a cryptographic hash?

  7. Q7.Throughput of FNV-1a (byte-loop) on modern CPUs?

  8. Q8.Where is FNV-1a still common?

  9. Q9.Is FNV-1a seeded by default?

  10. Q10.FNV-1a vs xxHash3, which has better SMHasher scores?

0 of 10 answered