Download free jailbreak firmwares for the iPhone 3G at iPhone Hacks and GuideMyJailbreak. Both websites also offer links to the Redsn0w application. Redsn0w is necessary to perform a jailbreak.
You must download a firmware and Redsn0w from either website to perform a jailbreak. Back up your personal data before jailbreaking.
To jailbreak your iPhone 3G, connect the iPhone to your computer, and launch Redsn0w. If using Windows 7 or newer, start the program in Windows XP compatibility mode by right clicking on it, selecting Properties and enabling Windows XP compatibility mode from the Compatibility tab. Run the application as an administrator.
Click the Extras button, and then select the firmware file that you downloaded by clicking the Select IPSW button. Go back to the main page on Redsn0w, and click Jailbreak. Select Cydia from the jailbreak options, and click Next. When the application asks you to put the iPhone in DFU mode, turn off the device, keep it plugged in, hold the power button for three seconds, and then hold power and home buttons for 10 seconds. Release the power button while pressing Home to launch the device in DFU mode.
When the iPhone reboots, Redsn0w begins the jailbreak installation. Once the process is complete, exit Redsn0w. Wait for your device to complete the process. Then launch Redsn0w again, complete the same steps but select Just Boot instead of Jailbreak. Put the phone in DFU mode again, and wait for the jailbreak to install.
Although the Digital Millennium Copyright Act makes it illegal to jailbreak iPads, it's still legal to jailbreak an iPhone 3G as of January 2016. However, you should make sure you're up to date on the latest federal and state laws to ensure jailbreaking is legal when you do it.