Resetting iphone to factory & getting into an old iphone with a passcode?

How can I reset my iphone 4? I sold it on ebay and don't want any old info on it. Also I have an old iphone id like to sell but I forget the passcode is thefe anyway to get into the phone?

To reset your iPhone go to setting -> general -> reset and it will reset your phone.

For your old iPhone 4: to restore it, the best way is to use a computer. Turn it off by holding the power button and "sliding to power off", or just hold the power and home buttons for 10 seconds together. The phone will turn off.
Now, hold the home button and immediately plug it into iTunes. If iTunes isn't open, open it. It will say "I found an iPhone in recovery mode" and your phone will display an iTunes icon with an arrow.
Then, proceed to restore and update it to the latest firmware.
This may not be faster than erasing it from your phone, but it will be more stable if you've jailbroken before. It's the only way I restore.

Second, (do I get double points?) to get into a phone with a passcode… I've tried before for various reasons and situations, and I did have luck getting into a 3Gs. But that was because I bruteforced the 4-digit number passcode they set.
If the passcode phone is jailbroken, it's possible to navigate to the location of the file that says "this phone is locked" and delete it. So in effect, you're telling the phone that there's no passcode. After a reboot, you can get it. (but that's assuming it's jailbroken). Trust me, after numerous discussion boards and much trial-and-error I know the best (and only way, if you're not already jailbroken) is to restore. Sad, but true.