Turn on or restart your Mac, then immediately hold down Command (⌘) + R
Release the keys when you see the Apple logo or a spinning globe.
When you see the macOS Utilities window, continue to the next section.
Erase your startup disk
Select Disk Utility from the utilities window of macOS Recovery, then click Continue.
Select your device or volume in the sidebar of Disk Utility.
Click the Erase button or tab.
Click Erase to begin erasing your disk.
When done, quit Disk Utility to return to the utilities window.
Choose Reinstall macOS (or Reinstall OS X) from the utilities window.
Click Continue, then follow the onscreen instructions. You'll be asked to select your disk. If you don't see it, click Show All Disks.
To verify eligibility to install macOS, your Mac serial number is sent to Apple, and you might be asked for your Apple ID.
Click Install. Your Mac restarts after installation is complete.
If you're keeping your Mac, complete the setup assistant with your own information.
If you're selling or giving away your Mac, press Command-Q to quit the setup assistant without completing the setup steps. Then click Shut Down. When the new owner starts up the Mac, they can use their own information to complete the setup.