Others mentioned microstamping but that's not the only method. Increasingly, ammunition being sold has serial numbers on both the bullet and the case.
The stamps are required to be on the firearm, not the ammunition. They're supposed to leave an identifiable mark on the ammunition when fired.