All new Macs include a feature called OS X Recovery that enables you to boot your computer from a recovery partition and perform system maintenance. Since most Macbooks don't have optical drives, OS X Recovery offers a reliable way to repair or restore OS X without installation DVDs. If you're restoring your Macbook before selling it or giving it away, you also need to deauthorize some of the user accounts associated with your system so that you can transfer them to a new computer.
Deauthorize your iTunes Store account if you're getting rid of your computer. Since only five computers can share the same iTunes account, you should always deauthorize a computer you no longer plan to use. Open iTunes, click "Store" and select "Deauthorize This Computer." Enter your Apple ID and password when prompted and click "Deauthorize."
Deauthorize any other software that limits your license to a certain number of computers, such as Photoshop or Lightroom. Refer to your owner's manual or the application's Help menu for the steps to deauthorize your account.
Back up your current installation to an external hard drive. This step is optional, and if your system isn't working properly, you should back up only the files you want to transfer to your new system. To clone your hard drive, connect an external drive to a USB port and open Disk Utility. Select "Restore," then drag the internal partition to the Source field and the external partition to the Destination field. Select "Erase Destination" and click "Restore." This process destroys all the data on the external partition, so use an empty disk or partition to store your backup.
Reboot your system into OS X Recovery. Click the "Apple" menu and select "Restart." While your computer is restarting, hold down "Command-R" to boot into OS X Recovery. If you need to connect to a Wi-Fi network after booting into Recovery, click the "Wi-Fi" menu, select your network and enter your password when prompted. If you're connected to a wired network, Recovery automatically detects your Ethernet connection.
Select "Reinstall OS X" and click "Continue." The recovery process requires an Internet connection to download the necessary files for restoring your Macbook. If you're restoring your computer to an upgraded version of OS X, Recovery prompts you to enter your Apple ID and password before downloading the installation files. Since the download copies about 4GB of files to your computer, it can take over 30 minutes with a high-speed connection.
Click "Restart" when the installation finishes. Your Macbook reboots into a fresh installation of OS X, and all your settings are restored to factory defaults.
Information in this article applies to OS X 10.7, 10.8 and 10.9. It may vary slightly or significantly with other versions.