You can use Internet Recovery Mode (Command + Option + R) to access the online macOS installer.
Here is an Apple article:
How to reinstall macOS - Apple Support
Here is an Apple article for properly preparing a Mac for sale:
What to do before you sell, give away, trade in, or recycle your Mac - Apple Support
FYI, if your Mac utilizes an internal Hard Drive or Fusion Drive, then the Apple instructions I linked are not sufficient to ensuring your personal data has been wiped since Apple's instructions assume a singe internal SSD, or a system that has FileVault enabled. If an internal Hard Drive is involved, then you either need to first enable FileVault & let the encryption process finish before using Disk Utility to perform a simple erase of the Hard Drive/Fusion Drive.
Or you need to use the "secure erase" feature in Disk Utility when erasing the internal Hard Drive (will break the Fusion Drive if equipped).....there is a separate button in Disk Utility's "Erase" section which offers a "secure erase" option of writing zeroes to the entire drive. If you do this with a Fusion Drive, then if you want to reinstall macOS, then you will first need to recreate the Fusion Drive after erasing the Hard Drive portion.