What really happens during a factory reset? Does it securely erase all data?
A factory reset reformats the phone's user-data partition, but it's not a "secure" wipe; it doesn't overwrite everything with zeroes.  If you want to be sure everything is erased, you can encrypt the phone first (which overwrites all the data with encrypted versions of itself), then do a factory reset (which sets up a new unencrypted filesystem).

(Update:  Most newer devices — those that shipped with Android 5 or later — are encrypted by default, so there's no need for a manual encryption step before wiping.  I expect that a factory reset should erase the master encryption key, rendering all the old data unreadable — though Google's documentation doesn't explicitly say so.)

Note that a factory reset leaves the phone's system partition (the "ROM") untouched.  If you've made any changes to the system partition (such as rooting), those will remain.