How do you stop floorboards from creaking?

Creaking is caused by the movement of the board against a finish nail.

For an existing condition… add finish nails on a slit angle at the areas of concern. For new installations, install glue on the underside of the floor boards in high traffic areas to prevent creaking.

If you have carpet carefully pull carpet and padding up and install minimum 3" deck screws where noise is coming from. Test by walking on questionable areas. Look for movement of substrate. If you have hardwood flooring and there is no access to the underside, find suspected areas and pre-drill for a long stainless finish nail at a 30 degree angle while placing sufficient weight on suspected area. Carefully drive nail and set. Cover with real wood putty (not plastic) and stain to match. Or if you don’t mind hard wood plugs you can pre-drill for deck screws and plug holes with real wood. Try your best to match the existing grain as you will be placing the new plug back into the countersunk hole. Use yellow glue to set plugs and trim plugs flush to floor surface with a plug cutting saw or sharp chisel. Sand, stain and finish.

If you have carpet there are special screws that snap off via a tool that you can screw directly through your carpet into the joists. Sometimes the squeak is not just between the subfloor and joists. Joist to joist can also cause it.