Launch iTunes from your programs list.
Connect your iPhone to the computer via USB and select it from the toolbar. If you are still using an old version of iTunes you can select your device from the sidebar.
Before continuing click the Back Up Now button to ensure your device is backed up before the restore.
If want to want to download and restore to the latest available firmware, click the Restore iPhone.. button from the Summary window.
If you have already downloaded the firmware ipsw for the firmware you would like to restore to, hold down the Shift key and click Restore iPhone.... You can find a list of firmware download links for the iPhone here.
Select the firmware ipsw file from your hard drive then click Open.
*Please note that you may not be able to downgrade to lower firmware version if Apple has stopped signing that firmware.
iTunes will ask you if you want to restore the iPhone to its factory settings. All of your media and other data will be erased. Click the Restore button to continue.
You may be shown the firmware's changelog. Click Next to continue.
Click Agree to agree to Apple's Software License Agreement.
If needed, iTunes will begin downloading the new firmware. This may take a while.
The firmware will then be extracted and installation will begin.
iTunes will inform you once the installation is complete and your iPhone will reboot.
You may be informed that there is a carrier update for your iPhone. If there is, click the Download and Update button.
The settings will be updated.
Click OK to acknowledge the successful installation.
You will then be welcomed to your new iPhone. You can choose to 'Set up as a new iPhone' or 'Restore from this backup'.
Select the option you'd like. If you chose to restore from backup, you can use the dropdown to select from previous backups.
Click the Continue button.
That's it! You have a refreshly restored iPhone. Click the Get Started button to view the device in iTunes.