When the Mac is sold, data and settings should be deleted. To do this, you should restart the Mac from the recovery system.

Apple is a company that always moves toward innovations. If you want a new Mac or have already bought, you can often sell the old one for a very good price. Since Macs are comparatively rare, the used prices are high and it is nonsense to keep the old device in the closet and let it become obsolete there.
Set Mac to factory settings: That’s how it works
Unfortunately, unlike Windows or iOS, macOS does not provide an easy, quick way to reset the Mac to factory settings in just a few clicks. Simple formatting is also not useful, sometimes even very problematic . Here, also because of the deep iCloud linkage, a little preliminary work is required. We’ll help you reset your Mac and prepare it for sale.
1st step:

We just assume that your new Mac is already set up and ready for use, and that you have transferred the data via a Time Machine hard drive, for example. All you have to do is delete the old device’s data and disconnect it from the iCloud. There are several ways to do this. First, you should boot your old Mac as usual. it was first step to How to Reset mac to factory settings in macbook pro macOS process.
2nd step:

Login now , if you have activated a login with username and password. If you turned them off, you will immediately see the desktop.
3rd step:

Now open the system settings and select ” iCloud ” here.
4th step:

Scroll down the Services list and uncheck ” Find my Mac ” by unchecking it.
5th step:

Enter your iCloud password and click Continue to disable the feature. These two steps are extremely important as otherwise your Mac will remain associated with your iCloud account, which may cause problems for the future owner.
6th step:

Now click ” Log out ” in iCloud Settings to turn off remaining iCloud services and remove the iCloud account from your Mac. The Mac asks what data you want to keep. Since you want to sell the Mac, you do not want to keep any data locally ! Remove all check marks and click ” Continue “.
7th step:

It may be that the Mac repeatedly asks if certain data types should be retained. Confirm each time with ” Delete from Mac “. The iCloud link is removed.
8th step:

Now you have to devote yourself to the other programs that are connected to the iCloud account. These are iTunes and the Mac AppStore. First open the Mac AppStore and select Store > Logout in the menu bar. Repeat with iTunes by opening iTunes and choosing Account > Log Out from the menu bar.This also stores and iTunes are disconnected.
9th step:

Now there is only one “real” method to really reset your Mac to factory settings: the so-called Internet Recovery or, if available, the supplied DVD. It will not only delete the Mac, but also reset it to the original macOS version. There are several variants:- The Mac has a DVD drive : Then there was a DVD included, you need to insert and then restart the computer. At startup, press and hold the ” C ” key to make the Mac boot from the DVD.- The Mac came without a DVD drive and therefore has no recovery DVD. In this case, you must hold down the [cmd] + [Alt] + [R] keys at system startup. A globe icon appears and the internet recovery starts. You may also need to enter a Wi-Fi password here.
10th step:

Either way, you will be taken to the base system recovery on your Mac. Depending on the macOS version, you have several options to choose from. But first you should format the hard disk. Therefore click on ” Disk Utility ” and then on ” Continue “.
11th step:

They are now in the Disk Utility. Select the Macintosh HD and click Erase .

In the following window macOS asks you for the name and the format. In the latter, select ” Mac OS Extended (journaled) ” and click Erase (ALL DATA ON THE MAC WILL BE REMOVED AND ERASED, THIS IS IRREVERSIBLE).
If necessary, you can also use the secure, but time-consuming secure deletion option only makes sense on Macs with a physical disk, that is, without an SSD. If you encrypted the Mac with FileVault, you will not need to delete it safely.
12th step:
After deleting, the recovery system reports that everything has worked. Click ” Done ” to complete the process. You can then exit the Disk Utility from the menu bar.
13th step:

In the main window, click on ” install macOS ” and then on ” Continue “.
14th step:
Confirm the installation of the system with ” Continue “. Then accept the license terms .
15th step:

Now select the Macintosh HD and click ” Install “.
16th step:
macOS or Mac OS X now installs itself, which may take a while, depending on the speed of the computer.
17th step:

When the installation is complete, the Mac may restart. He then shows the language selection of the macOS system . This means two things: On the one hand, the Mac is successfully reinstalled. And on the other hand, it is reset to factory settings. Do not worry anymore and do not set up the Mac . Instead, just turn it off with the on/off button.
Pack and sell mac
The Mac is now completely reset to factory settings and ready for sale. You can now clean and pack the device – or take pictures for Ebay and Co. The buyer receives the Mac in the same software state as if he had purchased a new device from Apple. The only difference is that he may still need to play the newer macOS versions, which should be in the buyer’s interest.
By the way: Simple resetting of the same macOS version over the normal system rescue (without Internet recovery) is not recommended: if the buyer did not acquire the appropriate macOS version in the AppStore, then he can not activate these. So always go through the Internet recovery or the included DVDs, otherwise it can cause problems and works to doing How to Reset mac to factory settings in macbook pro macOS go to bad result.
source