Bloom Filter Optimal Bit-Array Size (m) & Hash Function Count (k) Calculator

Size probabilistic Bloom filters for caches, LSM-trees, and deduplication.

Bloom Filter Memory Size (MiB) 8.57 MiB
Optimal Hash Functions (k) 10 hashes
Bits Allocated per Key (m / n) 14.38 bits/key
Total Bit-Array Length (Millions) 71.89 M bits
Inputs
Try:
keys
Expected number of distinct keys inserted (n).
%
Target false-positive rate percentage (e.g., 0.1% = 0.001).
Results & Graph
Bloom Filter Memory Size (MiB)
8.57 MiB
Optimal Hash Functions (k)
10 hashes
Bits Allocated per Key (m / n)
14.38 bits/key
Total Bit-Array Length (Millions)
71.89 M bits

Bloom Filter Memory Size (MiB)

Graph 1 • How the inputs feed Bloom Filter Sizing
Bloom Filter Optimal Bit-Array Size (m) & Hash Function Count (k) Calculator • Custom Domain Schematic (Cloud SRE & Distributed Systems) expectedfalsePosOut Expected Elements N: 5.00M keys • False Positive Rate Pct: 0.100 % BLOOM FILTER MEMORY SIZE ( 8.57 MiB • Optimal Hash Functions: 10 hashes • Bits Allocated per Key: 14.38 bits/key Eq: m_bits = −(n × ln(p)) / (ln 2)²;
Graph 2 • Bloom Filter Memory Size (MiB) as Expected Elements N changes (40% to 160% of current)
0 MiB 7.54 MiB 15.08 MiB 3.43 2.00Mkeys 5.14 3.00Mkeys 6.86 4.00Mkeys 8.57 5.00Mkeys 10.28 6.00Mkeys 12 7.00Mkeys 13.71 8.00Mkeys
Graph 3 • Expected Elements N and False Positive Rate Pct together Compares Bloom Filter Memory Size (MiB) when False Positive Rate Pct is shifted +25% (solid) vs. −25% (dashed).
0 MiB 6.38 MiB 12.76 MiB --- False Positive Rate Pct @ 75% 5.81 -30% 7.05 -15% 8.29 +0% 9.54 +15% 10.78 +30%
Summary: For 5,000,000 keys at 0.1% false-positive rate, allocate 8.57 MiB (14.4 bits/key) with k = 10 hash functions.
Summary: For 5,000,000 keys at 0.1% false-positive rate, allocate 8.57 MiB (14.4 bits/key) with k = 10 hash functions.
Interactive chart & math engine powered by CalculatorGraph

Formula: Bloom Filter Sizing Systems Engineering Formula

mbits = −(n × ln(p)) / (ln 2)²
khashes = round((m / n) × ln 2)
m_bits = −(n × ln(p)) / (ln 2)²; k_hashes = round((m / n) × ln 2)
  • expectedElementsN: Expected Elements N (keys)
  • falsePositiveRatePct: False Positive Rate Pct (%)

Frequently Asked Questions

Why does the calculator show the same 14.38 bits per key for 3,000,000 and 7,500,000 keys?

Because bits per key depends only on the false positive rate. The formula m = minus n ln p divided by (ln 2) squared is linear in n, so dividing by n removes it. At 0.1 per cent every key costs 14.38 bits whatever the total. Only the overall memory changes, from 5.14 MiB for three million keys to 12.85 MiB for seven and a half million.

Is the MiB figure the same as megabytes?

Not quite. A mebibyte is 2 to the power 20 bytes, slightly more than a decimal megabyte of one million bytes. The default bit array of 71.89 million bits is about 8.99 million bytes, which is 8.57 MiB. If your monitoring tool reports decimal megabytes it will show a larger number for the same filter. Neither is wrong, but compare like with like.

Can I lower the hash count to make lookups faster?

Yes, at a cost in accuracy or memory. With the bit array fixed at 14.38 bits per key, using 7 hashes instead of 10 raises the false positive rate above the 0.1 per cent target. If you want fewer hashes and the same accuracy, you need more bits per key. A gentler option is to accept 1 per cent, which this page sizes at 9.59 bits per key with 7 hashes.

What does a false positive actually cost me?

A false positive means the filter said 'maybe present' for a key that is absent, so your code does the expensive lookup anyway and finds nothing. The filter never gives false negatives for keys it holds. So the real cost is wasted disk reads, network calls or database queries. Multiply your lookup rate for absent keys by the false positive rate to estimate how many wasted trips you will make.

Should I size for the keys I have now or the keys I expect later?

Size for the most keys the filter will hold before it is rebuilt. A classic Bloom filter cannot grow, and overfilling hurts quickly. The default 8.57 MiB filter for five million keys reaches roughly 1.3 per cent false positives if you load 7,500,000 keys into it. Padding n by a reasonable margin costs memory in a straight line, which is much easier to live with.

Why is the optimal hash count not a whole number before rounding?

The optimum k equals log base 2 of one over p, and that is rarely an integer. For 0.1 per cent it is 9.97, for 1 per cent it is 6.64. The page rounds to the nearest whole hash. Near the optimum the error rate changes very little, so 10 hashes on the default filter gives about 0.09998 per cent, while 9 or 11 hashes gives about 0.102 per cent.

Does the formula assume anything about the hash functions?

It assumes each hash spreads keys uniformly and independently across the bit array. Good non-cryptographic hashes meet that well enough in practice. Weak or correlated hashes cluster bits, fill parts of the array faster and push the real false positive rate above what the page predicts. If you derive k positions from two base hashes, check your library documents that approach rather than inventing your own.

What target false positive rate should I start with?

Start from the cost of a wasted lookup. If a false positive means one extra in-memory check, 1 per cent or even 10 per cent may be fine. If it means a disk seek or a remote call, 0.1 per cent or lower is common. Remember the trade is modest: going from 1 per cent to 0.1 per cent takes five million keys from 5.71 MiB to 8.57 MiB.

Can I delete keys from the filter this page sizes?

No. A standard Bloom filter only supports adding keys and testing them. Clearing a key's bits would also clear bits that other keys depend on, creating false negatives. Counting Bloom filters replace each bit with a small counter so deletions work, but they need several times the memory shown here. Cuckoo filters are another option if deletions are central to your design.

How do I check the result against a library's own sizing function?

Most libraries take the expected count and error rate and return bits and hash count. Feed in 5,000,000 and 0.001 as a fraction, or 0.1 if the library uses percent, and compare. You should see about 71.89 million bits and 10 hashes. Small differences usually come from rounding the array up to whole bytes, words or a power of two, which only improves accuracy.

Five million keys at 0.1%: 8.57 MiB and ten hashes

Out of the box the calculator sizes a filter for 5,000,000 keys with a target false positive rate of 0.1 per cent. In plain terms, roughly one lookup in a thousand for a key that was never inserted will come back as 'maybe present' and send you to the slower store for nothing. The answer is 8.57 MiB of bit array, built from 71.89 million bits, which works out at 14.38 bits per key, probed by 10 hash functions.

You can check every one of those lines by hand. The natural log of 0.001 is about minus 6.908. The square of ln 2 is about 0.4805. Divide the first by the second, flip the sign, and you get 14.38 bits for each key. Multiply by five million and the bit array is 71.89 million bits long. Divide by 8 for bytes and by 2 to the power 20 for mebibytes and you land on 8.57 MiB.

The hash count comes from k = (m/n) ln 2. That is 14.38 times 0.693, or 9.97, which the page rounds to 10. Nothing here is a rule of thumb. It is the textbook optimum for a classic Bloom filter, and the engine reproduces it exactly.

Bits per key depends on the error rate, not the key count

Change only the number of keys and watch which lines move. With 3,000,000 keys the filter shrinks to 5.14 MiB and 43.13 million bits. With 7,500,000 keys it grows to 12.85 MiB and 107.83 million bits. In both cases bits per key stays at 14.38 and k stays at 10.

That is the most useful thing to understand about this formula. Once you fix the false positive rate, the cost per key is fixed too, and total memory is simply that cost times n. Doubling the keys doubles the memory. There is no economy of scale and no penalty either.

So the key count you type should be the number the filter will hold at the end of its life, not the number it holds today. A filter rebuilt nightly can be sized for one day of inserts. A filter that lives for a year inside a cache or a storage file must be sized for a year of growth, because a standard Bloom filter cannot be resized in place. You either rebuild it from the source keys or stack a new filter beside it.

Each tenfold drop in false positives costs about 4.79 bits per key

I ran the default five million keys at four different targets. At 10 per cent the filter needs 4.79 bits per key, 3 hashes and 2.86 MiB. At 1 per cent it needs 9.59 bits per key, 7 hashes and 5.71 MiB. At the default 0.1 per cent it is 14.38 bits, 10 hashes and 8.57 MiB. At 0.01 per cent it is 19.17 bits, 13 hashes and 11.43 MiB.

The pattern is regular. Every time you divide the error rate by ten you add the same amount of memory, about 4.79 bits per key, because ln 10 divided by (ln 2) squared is 4.79. Memory grows with the logarithm of how strict you are, which is why Bloom filters stay cheap even at very low error rates.

The hash count grows the same way, by about 3.3 for each extra factor of ten. That part is not free. Every insert and every lookup computes k bit positions and touches up to k different places in memory. A 13-hash filter does a third more work per query than a 10-hash one, and on a large array most of those touches are cache misses. If lookups are on a hot path, the memory figure is not the only cost to weigh.

Entering the rate as a percentage, not a fraction

The rate field takes a percentage. Typing 0.1 means 0.1 per cent, a probability of 0.001. The commonest mistake is to type the probability itself. Enter 0.001 and the page reads it as 0.001 per cent, which is a hundred times stricter than you meant. For five million keys that returns 14.28 MiB, 23.96 bits per key and 17 hashes, against the 8.57 MiB you actually needed.

The reverse slip happens too. Someone who wants 1 per cent types 0.01 and gets the 0.01 per cent answer of 11.43 MiB with 13 hashes. Neither error looks wrong at a glance, because both results are plausible numbers. A quick sanity check is the bits per key line: roughly 10 bits per key means about 1 per cent, roughly 14 means about 0.1 per cent, roughly 19 means about 0.01 per cent.

The page accepts a rate above 0 and below 50 per cent, and a whole number of keys of at least 1, and shows a message for anything else rather than guessing. A Bloom filter cannot promise zero false positives at any size, and a filter that is wrong half the time is barely filtering, so neither end describes a useful design. Realistic targets for caches and storage engines usually sit somewhere between 10 per cent and 0.01 per cent.

What happens when the filter holds more keys than planned

The 0.1 per cent promise only holds while the filter contains the number of keys you sized it for. Push more in and every new key sets up to 10 more bits, the array fills, and false positives climb much faster than the key count.

Take the default 8.57 MiB filter with 10 hashes and load it with 7,500,000 keys instead of five million. Using the standard estimate (1 minus e to the power minus kn/m) raised to k, the false positive rate rises from about 0.1 per cent to about 1.3 per cent, thirteen times the target, for only half again as many keys. Load it with ten million keys and it reaches roughly 5.7 per cent.

That is why it is worth padding n. If you expect five million keys but could plausibly see seven, size for seven. The extra memory is linear and predictable. The cost of underestimating is not. Many systems track how many items have been inserted and rebuild or roll over to a fresh filter once that count passes the design figure.

Rounding k, and why ten hashes is close enough

The exact optimum for the default is 9.97 hashes, which no real filter can use, so the page rounds to the nearest whole number. You might wonder how much that rounding costs. For a filter with 14.38 bits per key, the estimated false positive rate at 10 hashes is about 0.09998 per cent, essentially on target. At 9 or 11 hashes it is about 0.102 per cent. The curve is flat near the optimum, so being off by one hash barely matters.

There is a neat shortcut hidden in the two formulas. Substitute the first into the second and the bit array length cancels out, leaving k equal to log base 2 of one over p. For 0.1 per cent that is log2 of a thousand, 9.97. For 1 per cent it is log2 of a hundred, 6.64, which the page rounds to 7. You can work out the hash count in your head without ever knowing n.

In practice nobody runs ten independent hash functions. A common approach is to compute one or two strong hashes of the key and derive all k bit positions from them by combining the halves with a step. The sizing formula still applies, provided the derived positions are spread evenly across the array.

Turning 8.57 MiB into an allocation in code

The memory line is the bit array and nothing else. The keys themselves are never stored, which is the whole point, but your implementation will carry a small header, the hash seeds and any padding. The figure is reported in mebibytes, units of 2 to the power 20 bytes, which is what most memory tools show. A storage dashboard reporting decimal megabytes will show the same filter as a slightly larger number.

Many implementations round the bit array up, either to a whole number of 64-bit words or to a power of two so that a bitmask can replace a modulo. Rounding up only lowers the error rate, so it is safe. Rounding down is not, and if a library asks for bytes rather than bits it is easy to pass 71.89 million and get a filter one eighth of the size you meant.

Storage engines usually build one filter per file or per block, each with its own key count. In that case run the calculator per file. Bits per key is the number to carry into the configuration: a setting of 10 bits per key corresponds to roughly 1 per cent, while the default here corresponds to 14.38 bits and 0.1 per cent.

Remember too that a standard Bloom filter cannot forget a key. Clearing bits would break other keys that share them. If deletions matter, you need a counting variant that stores a small counter per slot, which multiplies the memory this page reports, or a periodic rebuild from the live key set.