If you know the Apple ID password, go to Settings > General > Transfer or Reset iPhone > Erase All Content and Settings
If you do not know the passcode, put the iPhone into Recovery Mode
Connect the iPhone to a Mac or Windows PC
On a Mac with Finder, or on a Windows PC with iTunes or Apple Devices, select the iPhone
Choose Restore when prompted
If Recovery Mode does not work, use DFU mode and restore the iPhone with Finder or iTunes
If Activation Lock appears after reset, enter the Apple ID and password previously used on the iPhone
If you forgot the Apple ID password, reset it at iforgot.apple.com
If you cannot remove Activation Lock, contact Apple Support with proof of purchase
