It would help to know the exact model of the Mac since the procedure is different for some Macs. You can get the exact model and version of macOS by clicking the Apple menu and selecting "About This Mac".
Boot the macOS installer and erase the whole physical drive if this is an Intel Mac. If booting a macOS 10.11+ installer, then you need to select the physical drive on the left pane of Disk Utility, then click the "Erase" tab on the right side and select GUID partition and MacOS Extended (Journaled). If you are installing macOS 11+, then you need to erase the physical drive as GUID partition and APFS (top option). You may also need to click "View" within Disk Utility and select "Show All Devices" so that the physical drive appears on the left pane of Disk Utility. If you are installing macOS 10.6 - 10.10, then you need to partition & format the physical drive instead:
https://www.owcdigital.com/assets/support/support-formatting-and-migration/Mac_Formatting_6-10.pdf
I highly recommend creating a bootable macOS USB installer so it gives you more options if something goes wrong since you do need a compatible Mac in order to create a bootable macOS USB installer:
How to create a bootable installer for macOS - Apple Support
But some Macs do support Internet Recovery Mode (Command + Option + R) which should boot to the most recent version of the online macOS installer that is compatible with your Mac. In theory at least, since sometimes this will just boot to the oldest macOS installer which originally shipped with your Mac.
Edit: Just to be clear.....erasing the drive will destroy all data on the drive. Since you were getting rid of the Mac before I doubt this will be a problem, but if you've been using the Mac it is possible you may have saved something important on the drive. Make sure you transfer any important files to external media before erasing the drive to perform the clean install.