http://www.jailbreakme.com
navigate to that site using safari on your device and it is automatic.
I have jailbroken both my 3GS and iPod touch. 3GS was iOS 4.0.1 and the touch was iOS 4.0.
Took about 5 minutes to load and the device didn't even have to reboot.