On Intel Mac: make a bootable USB macOS Installer, Option-boot to it, in Disk Utility > View > Show All Devices and erase the topmost device (not volumes under it) as APFS, then install macOS.
Create a bootable installer for macOS - Apple Support
...
p.s. that does not work on M-series Macs anymore because (at least in Tahoe) kernel process prevents erasing the whole device. It is still possible to make a bootable macOS installer via the Terminal but then Disk Utility seems to be accessed via internal Recovery anyway.
AFAIK in earlier macOS it was possible to erase the internal device in M-series Mac but after that the Mac must be Restored via DFU because internal disk is needed for boot process. BTW I just tested with Mac mini 2018 Sequoia Finder to Restore MacBook Pro M5 and it worked fine.
It is possible to erase M-series Mac's internal APFS Container or Volume with a desired name. When then exiting Disk Utility the Mac prompts to connect to Wi-Fi and the Mac is then Activated. Then install macOS.
Or just use the simplest way: Reset to factory settings: General > Transfer or Reset > Erase All Content and Settings... > Join Wi-Fi, Activate Mac > ...
...
p.s.2 In M-series Mac make sure NOT to use the DFU Port for the destination drive when installing macOS on an external drive (MacBook Pro M5: The leftmost USB-C port when you're facing the left side of the Mac).
In MacBook Pro M5 only the rightmost port on the left side seems to work when installing macOS on an external drive. Using other ports it seems to install but then fails to boot.
The external drive can then boot from all ports.
Deselecting "Copy account settings from username" performs a "clean install".
Selecting "Copy account settings from username" copies selected user account. But that does not copy any custom System settings.