Back up your data with Time Machine or another backup method
Sign out of iCloud
Sign out of Messages
Sign out of Music, TV, and Podcasts if needed
Restart the iMac
Enter macOS Recovery
On Intel iMac: restart and hold Command + R
On Apple silicon iMac: shut down, then press and hold the power button until startup options appear, then choose Options
In Recovery, open Disk Utility
Select the internal startup disk
Click Erase
Choose APFS if prompted
Confirm the erase
Quit Disk Utility
Select Reinstall macOS
Follow the on-screen instructions
Complete setup or shut down if you are selling or giving away the iMac
