Before you start
This test counts the movement signal your operating system passes to the browser. Two system settings sit between the sensor and that signal, and if either one is wrong, the number you get back will not be your DPI. Checking them takes under a minute.
Windows
Turn off pointer acceleration. Press the Windows key, type mouse settings, open it. Scroll down to Additional mouse settings and click it — a smaller window opens. Switch to the Pointer Options tab and clear the Enhance pointer precision checkbox.
That checkbox is pointer acceleration. With it on, the count depends on how fast you move, so the same physical distance gives a different answer every run.
Put pointer speed back to default. Same Pointer Options tab, the slider at the top. It has eleven notches — set it to the sixth, exactly in the middle. Every notch off centre multiplies or divides the movement your browser sees.
Reset browser zoom. Press Ctrl + 0 on this page. Zoom scales the reported movement along with everything else.
macOS
On Sonoma and later: open System Settings → Mouse → Advanced and turn Pointer acceleration off. Then press Cmd + 0 to reset browser zoom.
On older versions there is no switch for it. Open Terminal and run:
defaults write .GlobalPreferences com.apple.mouse.scaling -1
Log out and back in for it to take effect. Two things worth knowing before you do: your cursor will feel noticeably slower afterwards, and moving the Tracking Speed slider in System Settings silently undoes it. To go back, run the same command with a value between 0 and 3.
If you would rather not touch Terminal, LinearMouse and Mac Mouse Fix both do the same thing with a toggle.
One more thing
Move at a steady, unhurried pace during the test. Even with acceleration off, a fast jerk makes it harder to stop on the mark, and the whole measurement depends on stopping where you meant to.