This article describes how to restore your iPhone using iCloud or iTunes.
Restore iPhone with iTunes
Restore iPhone from iTunes backup: Connect iPhone to the computer you normally sync with, select iPhone in the iTunes window, and click Restore in the Summary pane.
To restore information from a backup, use one of the following methods after connecting your iOS device to the computer with which you normally sync. Right-click (or Control-click) the device and choose Restore from Backup; If you have a new phone, you can connect to iTunes and it will prompt to restore from your backup.
When the iPhone software is restored, you can either set it up as a new iPhone, or restore your music, videos, app data, and other content from a backup.
Restore iPhone with iCloud
You can use iCloud or iTunes to restore iPhone from a backup. iCloud is a new feature can only be found on iOS 5. iCloud requires iOS 5 on iPhone 3GS or later, iPod touch (3rd and 4th generation), iPad, or iPad 2; a Mac computer with OS X Lion; or a PC with Windows Vista or Windows 7. See Top 10 new features of iOS 5 here.
Restore iPhone from iCloud backup: Reset iPhone to erase all settings and information. Sign in to iCloud and choose Restore from a Backup in the Setup Assistant.
When you go through Setup Assistant on a new iOS 5 device, choose “Restore from iCloud Backup” and enter your iCloud account and password. You will see the three most recent backups for each of the devices on which you enabled Backup. Choose from which backup to restore.
After your device restarts, your settings and accounts are restored and Backup starts downloading your purchased music, TV shows, apps, books, Camera Roll, and other content*. You may be prompted to enter the passwords for all accounts enabled on your device.
A progress bar will appear underneath the apps that are being downloaded. To prioritize the restore of a specific app, tap its icon. Restore will attempt to download the same version of the app that you had installed previously. If that version is no longer available, the latest version of the app will be restored.
To check if the restore is complete, go to Settings > iCloud > Storage & Backup. Complete the setup assistant after erasing your device (by going to Settings > General > Reset > Erase All Content and Settings) or after starting your new device. When prompted to set up as new or to restore from previous backup, choose to restore from iCloud backup. Then enter your AppleID and password.
If you want to back up your iPhone, check this tutorial: How to Back up iPhone?