How to securely erase/format an iPhone for resale?
The built in “Erase all Content and Settings” function (found in the Settings app, under General → Reset) should be sufficient in virtually all cases.
The 3GS and later iPhones, 3rd generation and later iPod Touches and all iPads use hardware encryption, where all data is stored encrypted in their flash memory. On these devices the wipe function simply deletes the encryption key, rendering the data not much more useful than random noise. On devices without hardware encryption, the wipe function overwrites the entire user partition with ones. This is more secure with flash memory than doing the same on a hard drive (where some residual magnetic field can be detected from the previous data, although the chances of that are likely very low) — it's theoretically possible someone could retrieve some data, but it would be prohibitively expensive and time consuming.
Unless you're keeping extremely sensitive data on there (i.e. state secrets or evidence of a massive criminal conspiracy), I wouldn't worry about it once it's wiped.
Source: Apple Article HT2110 — iOS: Understanding 'Erase All Content and Settings'