The answer previously given is almost correct but two additional steps are missing - Backup your iphone data first ... via icloud And iTunes two backups is best. Then you need to disable "Find my device" under settings before you wipe / erase/ reset the iPhone. You can disable and unlink/remove your device from your icloud acct also prior to selling your phone -- this makes it better for the buyer later on .... do not forget to take your sim card also before selling the phone...
There are two things you should do: wipe out your data from the phone with a factory reset, and remove the sing from you Apple account to the device so it can be added back by the new owner. Here are the steps from Apple:
If you paired an Apple Watch with your iPhone, unpair your Apple Watch.
Back up your iOS device.
Tap Settings > iCloud. Scroll down and tap Sign Out. In iOS 7 or earlier, tap Delete Account.
Tap Sign Out again, then tap Delete from My iPhone and enter your password.
Go back to Settings and tap General > Reset > Erase All Content and Settings. If you turned on Find My iPhone, you might need to enter your Apple ID and password.
If asked for your device passcode or Restrictions passcode, enter it. Then tap Erase [device].
Contact your carrier for help transferring service to a new owner. If you aren't using a SIM card with your device, you can contact them to get help transferring service to the new owner.