Apple makes it simple to refresh you Mac prior to selling it.
First off make sure you backup/transfer all of your data.
Next, sign out of iTunes. Open iTunes on the top ribbon select Account > Authorizations > Deauthorize This Computer.
Then sign out of iCloud (you might want to do a copy or create an archive of your iCloud backup). Open System Preferences > iCloud uncheck the Find My Mac checkbox, click Sign Out.
If you are using iMessge, open the app. click Preferences > Accounts > your account name and click Sign Out.
Now you are ready to refresh your Mac. Restart holding down Option-Command-R keys, you can release the keys once you see an Apple logo.
In the OS X Utilities select Disc Utility and erase the drive steps in this link: https://support.apple.com/kb/PH22241?locale=en_US Close Disc Utility once done. Back at the OS X Utilities select Reinstall OS X, and follow the prompts. Once Mac is done installing the OS, it will restart to the welcome screen. at this point you can turn it off (press Command-Q), and you Mac is ready for the new owner.
According to Apple, it's a five-step process:
1. Create a backup.
2. Sign out of iTunes.
3. Sign out of iCloud.
4. Sign out of iMessage.
5. Erase and reinstall OS X.