Erasing a Mac to its factory settings right now requires formatting the startup disk and reinstalling macOS. But with the upcoming macOS Monterey, you have a much easier way to do this task. The Mac gets an "Erase All Content and Settings" through macOS Monterey. This feature will let you erase all user data and user-installed apps without needing to reinstall macOS, but you'll get a like-new Mac by the end of this process. It'll be helpful for those who want to sell or give their machines to someone else.
According to the macOS Monterey features page on Apple's website:
Erase all contents and settings
System Preferences now offers an option to erase all user data and user-installed apps from the system, while maintaining the operating system currently installed. Because storage is always encrypted on Mac systems with Apple silicon or the T2 chip, the system is instantly and securely "erased" by destroying the encryption keys.
Source: MacRumors