Before you sell, give away, or trade in your Mac, you should back up your computer, disable some features and services, and restore to factory settings by erasing the hard drive and reinstalling macOS.
Before you start erasing the disk, make sure you back up your data and log out of your accounts and services.
1. Restart in Recovery Mode
You’re going to erase your startup disk, so the first thing you need to do is start up from the recovery partition. To do this, click and choose Restart, or Shut down your Mac. When your Mac shuts off and then powers back on, press and hold Command+R keys until you see the Apple logo. Then release the keys and proceed to the next step.
2. Erase Data from Mac Hard Drive
While in Recovery Mode, you won’t see your usual login screen. Instead, you’ll see the “macOS Utilities” window. Here are your next steps:
a. In the macOS Utilities window, choose Disk Utility and click Continue.
b. Choose your startup disk and click Erase.
c. Choose Mac OS Extended (Journaled) as the format.
d. Click Erase.
e. Wait until the process is finished. When it’s done, go to the Disk Utility menu at the top and quit Disk Utility.
3. Reinstall macOS
Now, with your hard drive completely erased and free of any data, you can perform a clean install of macOS. You can do so while your Mac is still in recovery mode. From the same macOS Utilities window, choose Reinstall macOS (Reinstall OS X in older versions).