Before — always. Sanding is surface preparation: every nub, seam, and scratch gets erased first, because primer and paint magnify texture rather than hiding it. A nub sanded after painting takes the paint off with it.
The workflow is cut → sand → prime → inspect → paint. Primer is your inspector: a coat of gray surfacer reveals every blemish you missed while the fix is still one sanding pass away.
Go deeper in our sanding & surface prep guides.