Bloom filter sizer
A Bloom filter answers “have I seen this item?” in a fixed amount of memory. It never says no to an item it holds, but it sometimes says “maybe” to an item it has never seen. That is a false positive, and you choose how often it happens by choosing the size.
1,000,000 items at a 1% target need 1.2 MB (9,585,059 bits) and 7 hash functions, for a false-positive rate of 1%.
Your numbers
How many distinct items the filter will hold.
Share of lookups for items never added that still answer “maybe”.
Sizing
Try a 64-bit filter
Add words, then check words you never added. A check answers “maybe” only when all of its bits are set. With the starting words and 3 hash functions, try “cheese” or “salt”: never added, yet every one of their bits is set. Words can’t be taken out again, because a bit may be shared with another word.
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- applebits 16, 7, 62
- bananabits 47, 28, 9
- cherrybits 58, 5, 16
- grapebits 47, 50, 53
- lemonbits 6, 43, 16
- mangobits 41, 20, 63
- orangebits 51, 60, 5
- peachbits 48, 5, 26
What it shows
A Bloom filter has m bits and k hash functions. Adding an item sets the k bits its hashes point to. Checking an item looks at the same k bits. If any is clear, the item was never added. If all are set, it probably was.
Choose what to work out: the memory for a target false-positive rate, the rate for a size you have, or how many items fit. A 64-bit demo below lets you add words and watch false positives happen.
How to read it
- Hash functions is the whole number that gives the lowest rate, close to (m ÷ n) ln 2.
- Bits per item sets the rate. Each 10× lower false-positive rate costs about 4.8 more bits per item, whatever the number of items.
- The chart shows the rate for each number of hashes. Too few and items leave too little evidence. Too many and the bits fill up. The marker is the best k.
- In the demo, outlined bits belong to the word you are checking. “False positive” means a never-added word had every bit set by others.
Questions
Can a Bloom filter give a false negative?
Not if items are only added. Adding an item sets all of its bits, and nothing in a standard Bloom filter clears a bit, so checking that item always finds them set.
Can I remove an item from a Bloom filter?
Not from a standard one. A bit may have been set by several items, so clearing it could make other items look absent. Rebuild the filter, or use a variant that keeps a count per position instead of a single bit.
Do I need k different hash functions?
No. Kirsch and Mitzenmacher showed that two hash functions, combined as h1 + i × h2 for i from 0 to k − 1, give the same asymptotic false-positive rate. The demo filter here works that way, using MurmurHash3 with two seeds.
How accurate are these numbers?
They use the standard approximation p ≈ (1 − e^(−kn/m))^k, which is close for the large filters used in practice. Very small filters, like the 64-bit demo, can stray from it.
Learn it properly
Sources
Explore further
- Bloom filtersSam Rose’s interactive essay on how bloom filters work.
- Bloom filter calculatorThomas Hurst’s widely used calculator for filter size, hash count and false-positive rate.
Last updated
More tools
All tools- estimatorBack-of-envelope estimatorTurn daily users into requests per second, storage and bandwidth, with the working shown.Open tool
- simulatorConsistent hashing simulatorA hash ring with virtual nodes: key spread per node, and how many keys move when the cluster changes.Open tool
- estimatorQueue latency estimatorWhy latency explodes as servers get busy: utilisation, waiting time and Little’s law.Open tool