Step 1: Download redsn0w 0.9.5b5-5 from this link (Mac, Windows) and point it to iOS 4.0 (download if needed)
Step 2: Once you point redsn0w to iOS 4.0's IPSW file, click next and select what you'd like to be installed (Cydia, Custom boot logo, Verbose boot, Custom recovery logo, enable multitasking, enable home screen wallpapers, enable battery percentage). Once you select everything you want to be installed, click next.
Step 3: Here's where it gets extremely important make sure your device is both OFF and PLUGGED INTO the computer before you click next.
Step 4: Follow the directions on the screen to place your device into DFU mode. You'll notice that the screen goes completely blank for a few moments this is normal.
Step 5: After you place your device into DFU mode, that should be it on your part. redsn0w will take care of the rest. Once the jailbreak is finished, your device will reboot and that's it!
Credit: http://itsalltech.com/2010/08/11/how-to-jailbreak-ios-4-0-2-using-redsn0w/