1. Shut down your Mac, then start up from macOS recovery with Cmd (⌘) + R.
  2. When you’re asked to select an admin user you know the password for, choose Erase Mac from the Recovery Assistant menu in the menu bar.
  3. From the Erase Mac window, click Erase Mac, then click Erase Mac to confirm. 
  4. If your Mac restarts to a flashing question mark, press and hold the power button for a few seconds until your Mac turns off.
  5. Start up from macOS Recovery again, then reinstall macOS. For details, see How to reinstall macOS

If you can’t reinstall macOS because the installer doesn’t see a hard disk on which to install, you might need to change the format of the disk:

  1. Press Command (⌘)-Q to quit the installer.
  2. When you see the utilities window, select Disk Utility, then click Continue.
  3. Select the first item listed in the sidebar of the Disk Utility window. This is your built-in hard disk.
  4. Click the Erase button or tab on the right side of the window, then enter these details:
    • Name: Macintosh HD
    • Format: Mac OS Extended (Journaled)
    • Scheme (if shown): GUID Partition Map
  5. Click Erase, then click Erase to confirm.
  6. When the erase is complete, press Command-Q to quit Disk Utility and return to the utilities window. You should now be able to reinstall macOS successfully.