Performing a factory reset on an Android device does not remove OS upgrades, it simply removes all user data. This includes the following:
- Apps downloaded from Google Play Store, or otherwise side-loaded onto the device (even if you moved them to external storage.)
- Preferences and data for all apps, downloaded or pre-loaded on the device. This includes call/SMS/MMS logs, contacts, save games, etc.
- Personalized system settings (e.g. saved Wi-Fi networks and passwords, etc.)
- Any Google accounts you've added, along with saved credentials.
The factory restore does not touch the following:
- Contents of "external" storage (micro-SD Card, or for devices without it a part of internal memory that is set aside for this purpose) such as web downloads, photos and videos you've taken with the device, music you've copied over from your PC, documents, and other media. Exception is the apps that were moved to "external" storage.
- Core components such as system apps* (along with apps pre-loaded by your carrier and/or manufacturer into the system partition,) Android kernel, and bootloader. These core components are what defines the Operating System version.
- Network unlock status.
* Keep in mind that if you've updated any system apps via Play Store, those updates will be lost, and the apps will revert to the version that ships with the OS.