How can I downgrade my iPhone firmware from iOS 4 to 3.1.3?

How can I downgrade my iPhone firmware from iOS 4 to 3.1.3?

First of all, downgrading your iPhone firmware is only possible if you have saved your SHSH files. For those who took this precautionary step, use these instructions to downgrade.

1. Manually change the hosts file. To do this on a Mac find the hosts file in /etc and open the file with a text editor. Add the line "74.208.10.249 gs.apple.com" without quotes to the end of the file. On a Windows computer, find the hosts file in C:\Windows\System32\drivers\etc and edit the file in Notepad. Add the line "74.208.10.249 gs.apple.com" without quotes to the end of the file.

2. Check to make sure you have the iOS 3.1.3 firmware on your computer. Download the 3.1.3 firmware files for your device here:

iPhone 3GS
iPhone 3G

3. Now go ahead and put your iPhone into DFU mode.

4. In iTunes hold the Alt (Option) key down on the Mac or Shift key in Windows while clicking on Restore. Select the 3.1.3 firmware from the dialog box.

5. The iPhone will restore. If errors appear they can be ignored.

6. When the restore is finished your iPhone should boot normally. If the iPhone is stuck use a utility such as iRecovery to kick the device out of recovery mode.

Your iPhone is now running iOS 3.1.3.