Whether you're selling your iPhone or taking it for repair you should reset it to delete your accounts - including your Apple ID, Facebook, ebay, email and other accounts - and remove all your content including apps, photos and music. Here's how to reset an iPhone, iPad and iPod touch to factory settings. See also: How to set any song as your iPhone ringtone
How to reset iPhone or iPad: Summary
Reset an iPhone or iPad using Settings, General, Reset, Erase all content and settings. You will be prompted to enter your passcode and Apple ID before the process completes.
How to soft reset an iPhone or iPad
If your phone has locked up and you just want to restart it but none of the buttons work, then hold the power button and home button down at the same time until the device turns off and you see the Apple logo. Then let go and your phone or iPad will be back to normal.
How to back up an iPhone
Even if you use iCloud, it's sensible to make a full backup by connecting your iPad or iPhone to your computer, unlocking it, waiting for it to show up in iTunes, and then clicking on it in the left-hand pane. It should open the Summary screen, where you'll see a Backups section. Simply click the Back Up Now button. (Check the Encrypt iPhone backup box if you want all your passwords to be saved.)
How to reset an iPhone
Once that's done, you can begin the reset proces. It's also worth remembering to remove your SIM card before you pass on the iPhone or iPad on, as this may have information stored on it, and you might want to continue using it in a new phone or tablet.
Here we've used an iPhone running iOS 9 but it's exactly the same on an iPad and a very similar process in older versions.
Step 1. Tap Settings, then General. Scroll down until you see Reset. (In iOS 9 you can also pull down in Settings and search for Reset.)
Step 2. Tap Erase All Content and Settings. Depending on whether you've set a Passcode and / or a Restrictions Passcode (they are different) you might have to enter that code or password in order to erase and reset it. There is no way to reset the device unless you enter the code(s).
Step 3. Now you will have to enter your Apple ID password. This is so the account can be removed from your device, and Find My iPhone can be switched off. If you merely restore an iPhone via iTunes, you'll be asked to enter the Apple ID and password when it reboots. Resetting it using the method we're describing here will prevent the iPhone asking for an Apple ID when it restarts.
Step 4. The reset process can take a minute or two, after which you'll see the welcome screen asking you to swipe to continue. It's then ready to be sold on or taken to an Apple Store for repair.