Broad phase collision detection is the cheap first pass that discards object pairs too far apart to touch, so the costly shape tests run on only a few candidates. A uniform grid is the simplest way to build it.
This explainer sits within 2d game programming for beginners. It covers why the pass exists, the main ways to build it, a grid you can implement in plain JavaScript, and how to time the gain in a browser.
Why testing every pair is too slow
Testing every object against every other object is an O(n^2) approach, and it gets expensive as the object count grows. Ian Qvist’s overview of broad and narrow phase collision notes that a handful of simple algorithms can get away with this pairwise method in small scenes. The cost shows up once a game has crowds of bullets, particles, enemies or tiles.
The problem is the growth rate, not any single test. Each extra object must be compared with all the others, so the number of pairs grows much faster than the number of objects. Most of those pairs are far apart and could never touch, so the work is almost entirely wasted.
The first fix is to make each individual test cheaper. The same write-up points out that testing box against box is cheaper than testing many polygons against polygons. That helps, but it does not change the O(n^2) shape of the loop. Reducing the number of pairs is the only way to change that shape, and that is the job of the broad phase.

The two-stage pipeline: broad phase and narrow phase
The broad phase is the first stage of collision detection. It reduces the number of pair tests by proposing only the pairs that might be touching. Qvist’s overview describes it as the way to cut the amount of tests in a collision system.
What the broad phase decides
The broad phase only keeps track of the distance between objects. It does not know where two shapes intersect or how deeply. It answers one question, which is whether two objects are close enough to deserve a closer look. After it runs, the system is left with a couple of pairs that need further testing, as Qvist puts it.
Each object is usually represented by a bounding box. This is a box that does not rotate and encloses the whole object. Because it never rotates, it can be compared with another box using a few cheap comparisons. A false positive costs only a wasted narrow phase test. A false negative is a missed collision, so the box must fully enclose the object.
What the narrow phase does
The narrow phase takes two polygon shapes and finds where they intersect. A physics engine also needs to know how deep the shapes have penetrated each other, along with the collision normal and position. Those values are what let the engine push objects apart and change their motion. That follow-up work is covered in collision response 2d game. Narrow phase shape tests are a separate topic, so this page stops at the list of candidate pairs.

Common ways to prune pairs
Every broad phase technique trades some bookkeeping for fewer pair tests. The right choice depends on how objects are distributed and how they move.
| Approach | How it narrows pairs | Planning use |
|---|---|---|
| Uniform grid | Divides the world into equal cells and pairs objects that share a cell. | Best first choice when objects are similar in size and spread across a bounded area. |
| Spatial hashing | Maps cell coordinates to buckets, so only occupied cells are stored. | Suits large or unbounded worlds where a full grid array would be mostly empty. |
| Quadtree | Subdivides crowded regions into smaller regions. | Suits uneven distributions, such as dense clusters in an otherwise empty map. |
| Sweep and prune | Sorts object extents along an axis and pairs only those whose ranges overlap. | Suits scenes where objects move a little each frame, so the sorted order changes slowly. |
Qvist’s list of broad phase algorithms gives both sweep and prune and spatial hash as O(n log(n)) algorithms. The Planning use column is a practical reading of how each method works, not a benchmark result.
Move to spatial hashing when the world is too large to allocate as an array. Consider a quadtree when objects bunch up in a few places while most of the map stays empty. Sweep and prune is worth a look when one axis dominates, such as a side-scrolling level.
Building a uniform grid
A uniform grid splits the play area into equal square cells and records which objects overlap each cell. Two objects can only collide if they share at least one cell, so the narrow phase receives only those pairs.

Choosing a cell size
Cell size is the one setting that matters. If cells are much smaller than the objects, each object spans many cells and insertion work grows. If cells are much larger than the objects, many objects share a cell and the pair list approaches the brute-force loop again. A cell size close to the size of a typical object is a sensible starting point. Adjust it by timing the result.
Insert and query steps
The grid needs two operations, and both fit in a few lines of JavaScript using a Map keyed by a cell string.
- Clear the grid each frame. Empty the map at the start of every update. Rebuilding is simple and works well for objects that move every frame.
- Compute the cell range of each bounding box. Divide the box’s left, right, top and bottom edges by the cell size and round down with Math.floor. This gives the first and last column and row the box touches.
- Insert the object into every cell in that range. Build a key from the column and row, for example a string joining the two with a comma. Fetch the array for that key, creating it if absent, and push the object in.
- Query by walking the occupied cells. For each cell holding more than one object, pair up the objects inside it. These are the candidate pairs.
- Remove duplicate pairs. An object that spans several cells can meet the same neighbour in more than one cell. Give each object an id and record each pair under an ordered id key, so it is handed on only once.
- Hand the candidates to the narrow phase. Run the exact shape test on each surviving pair and pass any contacts to your response code.

Because the grid stores only references, rebuilding it each frame is cheap compared with the shape tests it avoids. Static objects such as walls can be inserted once and kept, while only moving objects are cleared and reinserted.
Measuring the gain in the browser
Measure the grid before trusting it, because the benefit depends on object count, object size and cell size. A grid has overhead, and a scene with few objects may not repay it.
- Keep the scene identical. Use the same object count, positions and seed for both runs, so only the broad phase differs.
- Time the collision step alone. Wrap it with performance.now() calls and average over many frames. Keep other per-frame work out of the timed section, including anything driven by keyboard input handling game code.
- Compare against the brute-force loop. Record the pair loop first, then the grid version, and compare the collision step time and the candidate pair count.
- Confirm in the profiler. The browser’s performance panel shows whether collision work still dominates a frame once the grid is in place.
- Scale the object count. Repeat at several counts. The pairwise loop is O(n^2), so the gap should widen as the count rises.
Record your own figures rather than relying on someone else’s. Frame times depend on the device, the browser and how much else the game does.
Frequently asked questions
What is the broad phase in collision detection?
It is the first stage, which uses cheap tests on bounding boxes and distances to reduce the number of pair tests. Only the few pairs it leaves go on to the narrow phase.
Why are checks between all pairs too slow?
Testing every object against every other is an O(n^2) approach. Each added object must be compared with all the others, so the cost grows far faster than the object count.
Is a uniform grid always better than sweep and prune?
No. A grid suits similar-sized objects in a bounded area. Sweep and prune suits scenes where objects shift little between frames, and Qvist lists it as O(n log(n)). Time both on your own scene.
Does the broad phase find exact contact points?
No. It only keeps track of the distance between objects. Penetration depth, the normal and the collision position come from the narrow phase.



