Sweep and prune
A broad-phase algorithm that sorts objects' bounding boxes along each axis and only tests pairs whose intervals overlap on every axis.
Testing every object against every other is O(n²) and hopeless with thousands of bodies. Sweep and prune (also "sort and sweep") projects each bounding box's start and end point onto the x, y and z axes, sorts the lists and sweeps through them; two boxes can only collide if their intervals overlap on all axes. Everything else is pruned at once.
The trick is temporal coherence — objects move only a little between frames, so the sorted lists are nearly sorted already and an insertion sort runs close to linear. The method came out of the I-COLLIDE library by Ming Lin and Dinesh Manocha in the early 1990s and sits in practically every physics engine as a cheap first pass before the expensive exact phase.