Skip to content
CoreVerified ImplementationLive Benchmarkable

FNV-1a Hash

Fast non-cryptographic 32-bit/64-bit byte-stream hash function that XORs each byte into the state before multiplying by the FNV prime.

Quick Facts

Compact metadata for implementation and discovery.

Category
Cryptography
Difficulty
Beginner
Family
Non-Cryptographic Hash
Tier
Core
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
2
Code example
Ready
Visualization
Ready
Aliases
Fowler-Noll-Vo Hash, FNV1a-32

Overview

Fowler-Noll-Vo (FNV-1a) is a lightweight non-cryptographic hash function widely used in hash tables, symbol tables, and Bloom filters. By XORing the input byte before multiplying by the FNV prime (0x01000193 for 32-bit), FNV-1a achieves better avalanche dispersion on small integer and ASCII keys than FNV-1.

Core Concepts

offset basisFNV prime multiplicationavalanche effect

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(n)

Average

O(n)

Worst

O(n)

Space

O(1)

Interactive Runtime & Memory Budget Calculator

Estimate wall-clock latency, operation count, and working memory for FNV-1a Hash across input scales.

Input Scale N:
JIT-compiled JS/TS (~350M primitive ops/sec)
Est. Average TimeO(n)

428.6 µs

60 FPS Frame-Safe (<16ms)~150.0k ops
Est. Worst-Case TimeO(n)

428.6 µs

60 FPS Frame-Safe (<16ms)~150.0k ops
Est. Working MemoryO(1)

128 B

L2/L3 Cache FriendlyN=100,000

When to Use

  • Fast non-cryptographic 32-bit FNV-1a XOR-multiply hash function for in-memory hash table string lookups, bloom filters, and checksums.
  • Use FNV-1a when you need a tiny, zero-dependency, deterministic hash for short strings and hash tables.

When Not to Use

  • Never use FNV-1a for password hashing, cryptographic signatures, or untrusted network keys vulnerable to HashDoS (use SipHash or SHA-256).

What It Does

  • Initializes state to the 32-bit FNV offset basis (0x811c9dc5)
  • For each byte: XORs byte into low 8 bits, then multiplies modulo 2^32 by FNV prime 0x01000193

Use Cases

  • Fast in-memory hash table bucket indexing
  • Bloom filter and Count-Min Sketch hash mixers
  • Compiler identifier interning and checksums

Inputs

  • Byte array or UTF-8 string

Outputs

  • Unsigned 32-bit integer digest

Key Formulas (1)

FNV-1a Step

h_{i} = ((h_{i−1} \oplus bi) \times 16777619) \bmod 2^{32}
h_{i} = ((h_{i-1} \oplus b_i) \times 16777619) \bmod 2^{32}

32-bit FNV-1a round update.

Pseudocode

  1. 1.Set hash = 0x811c9dc5 (2166136261)
  2. 2.For each byte b in input:
  3. 3. hash = hash XOR b
  4. 4. hash = (hash * 0x01000193) mod 2^32
  5. 5.Return unsigned 32-bit hash

Verified Implementation & Unit Tests

Verified Implementation

Tested TypeScript and Python 3 implementations paired with unit tests covering edge cases, duplicate keys, and boundary conditions.

/**
 * FNV-1a 32-Bit Non-Cryptographic Hash — UTF-8 byte-stream XOR-then-multiply with prime 16777619
 * Time: O(n) | Space: O(1)
 */
export function fnv1aHash32(input: string | Uint8Array): number {
  const bytes = typeof input === "string" ? new TextEncoder().encode(input) : input;
  let hash = 0x811c9dc5;
  for (let i = 0; i < bytes.length; i++) {
    hash ^= bytes[i];
    hash = Math.imul(hash, 0x01000193) >>> 0;
  }
  return hash >>> 0;
}

Canonical Example

Input
"foobar"
Output
0xbf9cf968 (3214735720)
Explanation
Each ASCII byte is XORed and multiplied by 16777619 modulo 2^32.

Implementation Notes

  • Official IETF FNV test vectors: fnv1a_32("") = 0x811c9dc5, fnv1a_32("a") = 0xe40c292c, fnv1a_32("foobar") = 0xbf9cf968.

Common Pitfalls

  • Using standard JS floating-point multiplication (hash * 0x01000193) instead of Math.imul, which loses low bits above 2^53.

Interactive Mechanism Walkthrough & State Debugger

Array Partition & Ordering Trace

Byte-by-byte XOR and 32-bit modular prime multiplication.

38
[0]
14
[1]
52
[2]
23
[3]
61
[4]
19
[5]
44
[6]
29
[7]
step1 / 5
cursor i0 (val=38)
pivot / key61
sorted prefix0 / 8 items
invariantPartitioning prefix
Step 1 of 5: Set hash = 0x811c9dc5 (2166136261)
array-sort

Notes

In JavaScript/TypeScript, use Math.imul(hash, 0x01000193) >>> 0 to preserve exact 32-bit unsigned modular multiplication.

Sources (1)

What each reference supports for this entry.

Eastlake, Fowler, Noll, Vo — The FNV Non-Cryptographic Hash Algorithm (IETF Draft)

Documentation

Specification and official test vectors for FNV-1 and FNV-1a.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Used byHash Table

Provides fast bucket indexing for open-addressing and chained hash tables.

Alternative toSipHash

Faster on short trusted keys, whereas SipHash protects against adversarial HashDoS collisions.

Tags

HashingHash TableBitwiseFast Hash