If you have an iPhone 3G, iPod Touch 2g (non-MC version) jailbreaking 4.0 is very simple using redsn0w both on mac and windows by the iPhone Dev Team. This guide was made using a mac and the screenies are from a mac but the process is identical on windows so you can follow this guide as well. Before you continue update your iPhone 3G or iPod Touch 2g (old bootrom) to 4.0 using iTunes.
To check your iPod Touch 2g bootrom run f0recast (mac | win). If it says Tethered Yes then you can not currently jailbreak 4.0.
Now download what you need.
Firmware:
iPhone 3G 4.0 (follow this guide if downloading with Safari)
iPod Touch 2G 4.0 (follow this guide if downloading with Safari)
Software:
Plug in your device and turn it off. Run redsn0w. Click browse.
Find the 4.0 firmware IPSW you downloaded for your device. Select it and click Open.
redsn0w processes the IPSW.
IPSW successfully identified! Click Next.
redsn0w does its magic.
Choose your options. Click Next
Make sure your device is plugged in and off. Click Next.
Hold down the power button for 3 seconds.
Continue holding down the power button while you press the Home button. Hold both for ten seconds.
Keep holding the Home button but release the power button.
You can release the home button when redsn0w starts working its magic.
All done! click Finish.