Back up your iPhone to iCloud or a computer
Open Settings
Tap General
Tap Transfer or Reset iPhone
Tap Erase All Content and Settings
Enter your passcode if prompted
Enter your Apple ID password if prompted
Tap Erase Now
Wait for the device to finish wiping
Set up the iPhone again or leave it at the setup screen
