Back up any data you want to keep
Sign out of Apple ID if possible
Open Settings
Tap General
Tap Transfer or Reset iPhone
Tap Erase All Content and Settings
Enter your passcode
Enter your Apple ID password if prompted
Confirm erase
Wait for the iPhone to restart and erase completely
