Identity theft in today's world is a big criminal business. You have to be hyperaware of what each of your devices can tell about you, your habits, your bank accounts, and more. Probably the biggest hub for all that information is your smartphone; you definitely don't want your address, passwords, photos ending up in the wrong hands. Luckily, before you trade-in or recycle it, you can wipe it clean. Bad guys won't be able to get anything; good guys will be able to use their new refurbished phone with no problems.
If you have an iPhone, Apple has built everything you need to turn off into the Erase command now. More on that in a moment, but before you start, you should make a backup!
You have two options for backing up: iCloud and iTunes (on your Mac or PC).
iCloud is probably the easiest, is done via WiFi, and you can restore everything except secure information like app sign-ins and such. To do this, go to your iCloud settings -- under your name/account in iOS 10.3 and later, or just under iCloud in earlier versions of iOS.
Choose iCloud Backup and Back Up Now. You'll want to plug in the phone to ensure it doesn't run out of juice while it's doing the work.
If you want a lot more settings, passwords, and more backed up so you don't have to do a lot of set up on your new phone, then plug the phone into your Mac or PC and use iTunes. Be sure to select "Encrypt iPhone Backup" and then enter a password to use. This should probably be different from your comptuer or phone password; it's just for the backup file.
All backed up? Good! Time to erase that phone! The Erase command now turns off things like Find My iPhone, the App Store, and more, so anyone buying your recycled phone will be able to use it. Just go to the Settings, then choose General and Reset. Tap on "Erase All Content and Settings." It will ask you for your iCloud password, and once you enter that, the phone will turn off all iCloud services and erase everything.
If you'd rather sign out of everything yourself, or if you have an iOS older than version 10, you can still do that. The main ones to turn off are Find my iPhone and iCloud itself. You can find this under Settings in the iCloud section. Do Find My iPhone first, then go back and tap "Sign Out" to get that iCloud service shut down. Signing out of iTunes and the App Store on the main settings screen is probably a good idea, too. Then, erase away!
There is one more step to do, especially if you are moving to another iPhone. Clear the old iPhone out of your AppleID account so you don't get any confusion later if one day you find yourself in there setting up account information. Go to http://appleid.apple.com and log in using your AppleID. This is usually the same as your iCloud/App Store name and password, but there are tools there to help you recover them if needed. Once logged in, you'll scroll down to Devices, click on the iPhone you erased, and then chose to "Remove" it from your account.
And you're done!
Apple encrypts everything on an iPhone based on your passcode. Even if there is anything left after erasing, the keys to unlock that data are gone. Depending on the length of your passcode, bad guys could take a thousand years and more to figure it out! Your information is safe, and, even better, the next owner of that phone will be able to set it up as their own with no troubles at all.