Hash table collisions explained in plain terms means understanding what happens when two different keys land in the same slot of a table. The central question is how a structure built on the idea that every key has its own place can cope when two keys claim the same one, and the answer is that collisions are not a bug to be eliminated but a fact to be managed, because the mathematics guarantees they will happen.
A hash table collision occurs when a hash function maps two different keys to the same index, and the table must store both without losing either. The two classic answers are chaining, which keeps a list of entries in each slot, and open addressing, which looks for another empty slot nearby, and the choice between them shapes the performance of nearly every hash table in use.
The idea is a good reminder that even the fastest data structure in computing has a wrinkle, and that the wrinkle is handled with elegance rather than brute force. This article explains what collisions are, how they are resolved, and which approach fits which workload.
Key takeaways
- A collision happens when two keys hash to the same slot.
- Collisions are unavoidable, because the key space is larger than the table.
- Chaining stores a list of entries in each occupied slot.
- Open addressing probes for another empty slot nearby.
- The load factor decides when a table must grow and rehash.
What a hash table collision is
A hash table works by passing each key through a hash function, which turns it into a number, and using that number, modulo the size of the table, as the index where the key’s value is stored. Looking a key up means hashing it again and going straight to that slot, which is why hash tables answer queries in constant time on average. The whole design rests on the hash function spreading keys evenly across the slots.
A collision is what happens when that spreading fails for a particular pair of keys. Two keys with different values can still produce the same index, either because the hash function gave them the same output or because two different outputs landed in the same slot after the modulo. Either way, the table now has two entries competing for one place, and it must keep both.
The birthday paradox shows why collisions are unavoidable rather than rare. In a table of a thousand slots, a collision becomes likely after only about forty keys, because the number of pairs grows far faster than the number of keys. A hash table that holds thousands of entries will contain many collisions, and the resolution strategy is what keeps it fast regardless. Our guide to hashing explains how hash functions are designed to spread keys as evenly as possible.
Chaining: lists in every slot
Chaining resolves a collision by storing a small list, usually a linked list, in each slot, and adding every colliding key to the list for its slot. Looking a key up means hashing it, going to its slot, and walking the list until the key is found, which costs as much as the list is long. When the table is lightly loaded, most lists hold one entry and lookups are effectively constant time.
Chaining has a graceful way of degrading. As more keys arrive, the lists grow longer, and lookups slow down gradually rather than failing suddenly, which makes the behaviour predictable and easy to reason about. The table can even hold more entries than it has slots, because a slot is a list of any length, and the only penalty is time.
Modern implementations improve on the plain linked list by switching a long chain to a balanced tree once it passes a threshold, which caps the worst case at logarithmic time instead of linear. That hybrid is what the standard hash map in Java does, and it is a good example of a simple idea being refined rather than replaced.
Deletion in a chained table is straightforward, because removing an entry means unlinking it from its list, and no other entry is affected. That simplicity is one of chaining’s quiet advantages, and it is part of why the method is the default in many languages and libraries.
Open addressing: finding another slot
Open addressing takes the opposite approach: every entry lives directly in the table, and a collision is resolved by probing, which means looking at other slots in a fixed sequence until an empty one is found. The probe sequence might step through neighbouring slots, jump by a growing offset, or hash the key a second time to decide the step size, and each variant has different clustering behaviour.
Linear probing, which checks the next slot, then the next, and so on, is the simplest variant and the fastest in practice when the table is lightly loaded, because neighbouring slots sit in the same cache line. Its weakness is primary clustering, where a run of occupied slots grows longer and longer, so that a new key landing anywhere in the run must walk to its end.
Quadratic probing jumps by one, then four, then nine, which spreads the probes and breaks up the clusters, while double hashing uses a second hash function to choose the step size, which spreads colliding keys across the table most evenly of all. The trade is complexity: each improvement costs a little more code and a little more thought about the probe sequence.
Deletion in open addressing is the tricky part, because removing an entry leaves a hole that a later search might mistake for the end of a probe sequence. The standard fix is a tombstone, a marker that says this slot once held an entry, so searches pass through it while inserts may reuse it. Tombstones accumulate over time, which is one more reason open addressing tables are resized before they fill up.

Chaining versus open addressing
The choice between chaining and open addressing comes down to how the table will be used. Chaining degrades gracefully, deletes cleanly, and tolerates high load factors, while open addressing is faster when the table is lightly loaded, because everything sits in one flat array that the processor’s cache loves. Both are correct, and the workload decides.
The table below sets out the main contrasts between the leading approaches.
| Aspect | Chaining | Open addressing | Perfect hashing |
|---|---|---|---|
| Where entries live | In lists attached to slots | Directly in the table | Directly, collision-free |
| Lookup cost | Constant on average, list length | Constant on average, probe length | Constant, guaranteed |
| Deletion | Simple, unlink from the list | Needs tombstones | Not supported in general |
| High load factor | Degrades gradually | Degrades sharply, must resize | Built for a fixed set |
| Best for | General hash maps, heavy loads | Caches, lightly loaded tables | Static key sets, read-only |
The practical result is that chaining is the safer default for a general-purpose map, while open addressing wins for caches and other tables that stay lightly loaded and are rebuilt often.
Where collision handling matters
Language runtimes live or die by their collision handling. The hash maps in Java, Python, and Go serve nearly every program written in those languages, and their designers chose chaining or open addressing after careful measurement, because a slow hash map slows down everything built on it. Our guide to consistent hashing explains how the same ideas scale out to distributed systems.
Caches use open addressing because they are rebuilt often and kept lightly loaded, which is exactly the workload where probing shines. A cache that evicts entries constantly has no need for chaining’s graceful degradation, and it gains real speed from the flat array layout that keeps lookups in the processor’s cache.
Databases use hash tables for joins, grouping, and in-memory indexes, where the collision strategy affects query times directly. A hash join that processes millions of rows needs its lookups to stay constant time, and the load factor at which the table resizes is a tuning knob that database engineers set with care. Our guide to Memcached shows how hash-based caching serves entire applications.
Security is the dark side of collisions. An attacker who can craft keys that all hash to the same slot can turn a hash table’s constant-time lookups into linear scans, a denial-of-service attack known as hash flooding. Modern hash functions use a random seed per process, so the attacker cannot predict the collisions in advance, which is a reminder that a data structure’s worst case is a security question as well as a performance one.
Strengths and limits
The greatest strength of modern collision handling is that it makes the hash table’s average case its practical case. With a good hash function, a sensible load factor, and a sound resolution strategy, lookups stay constant time for workloads of any size, which is why the hash table is the most used data structure in computing.
It is also a strength that the two strategies complement each other. Chaining covers the cases where open addressing struggles, and open addressing covers the cases where chaining is slower, so an engineer who understands both can pick the right one for each situation rather than accepting a single default.
The limits are real, though. A hash table offers no ordering, so range queries and sorted scans need a tree instead, and a bad hash function can defeat even the best resolution strategy. Collisions are a fact of life, and the structure’s speed depends on managing them rather than pretending they do not happen.
Hash table collisions checklist
- Expect collisions, they are guaranteed by the birthday paradox.
- Use chaining for general maps and heavy loads.
- Use open addressing for caches and lightly loaded tables.
- Resize the table when the load factor passes about 0.7.
- Rehash every entry when the table grows.
- Use tombstones for deletions in open addressing.
- Seed the hash function randomly to resist hash flooding.
- Measure lookup time under your real key distribution.
- Remember a hash table gives no ordering of keys.
Frequently asked questions
What is a hash table collision in simple terms?
It is what happens when two different keys are mapped to the same slot in a hash table, so the table must store both without losing either.
Why are hash table collisions unavoidable?
Because the number of possible keys is far larger than the number of slots, and the birthday paradox means collisions become likely after surprisingly few keys.
What is chaining in a hash table?
It is a resolution strategy that stores a list of entries in each slot, so colliding keys simply join the list for their shared slot.
What is open addressing in a hash table?
It is a resolution strategy that probes other slots in a fixed sequence until an empty one is found, keeping every entry directly in the table.
What is a load factor?
It is the number of entries divided by the number of slots, and it decides when a table must grow, usually when it passes about 0.7.
When should I not use a hash table?
When the keys need ordering, range queries, or sorted scans, where a balanced tree is the right structure instead.
The bottom line
Hash table collisions explained in one line is this: two keys will share a slot, so keep a list there or probe for another, and resize before the table fills up.
It is the wrinkle that makes the fastest data structure in computing work in practice, and the reason a little planning about collisions pays off so well.
This article is general information about how hash table collisions work, not advice about choosing a data structure for a particular system.







