Learn about causes and fixes for this problem.
Recording gaps are typically caused by an overloaded computer, or by broken cables and connectors.
Audacity is for the most part a single-core application. On modern multi-core systems it typically isn't possible to bring it down with normal computer use, but it may be bottlenecked by hard drive access, and by creating very complex projects with many realtime effects.
You may be able to see the bottleneck in the performance tab of the task manager (macOS: activity monitor). Typical bottlenecks are CPU or storage.
There are several parts on the path between a mic and Audacity which can break: The mic itself, the cable, the port for the cable on the computer, and the computer itself.
Close all other programs which aren't necessary to run for your recording task.
Increase the buffer length in Audio Setup -> Audio Settings.
Disable playback of other tracks, as well as input monitoring during recording (Transport -> Transport options -> Hear other tracks during recording and Enable audible input monitoring)
End background tasks, or wait for them to finish. These often may be antivirus scans, system updates or updates of other applications (like games).
Record to a hard drive which still has a lot of capacity.
End background tasks, or wait for them to finish. These often may be antivirus scans, system updates or updates of other applications (like games).
Record to a hard drive which is directly attached to the computer (as opposed to a USB hub or similar).
Reduce the amount of data being written. In particular:
Try using a different cable.
Try plugging the cable into a different port on the computer
Try using a different microphone.
Try using a different computer.
If the troubleshooting steps aren't working for you, feel free to ask in our communities:
Render all tracks in Audacity via Tracks -> Mix -> Mix and Render.
Shrink the size of the Audacity window and zoom out.
Record Mono instead of Stereo (Audio Setup -> Recording channels)
Record in 16-bit instead of 32-bit (Audio Setup -> Audio Settings)