This article explains how to format the internal memory of an iPhone by deleting all the data it contains and effectively restoring the status of the device to the time you purchased it while also restoring the factory default configuration settings. In addition, it also explains how to restore your data using an iCloud backup.
Steps
Method 1 of 2: Backup and Erase an iPhone

Step 1. Launch the Settings app
It features a gray gear icon (⚙️). It is normally visible directly on the Home screen.

Step 2. Select your Apple ID
It is displayed at the top of the "Settings" menu and is characterized by your name and the profile picture you have chosen.
- If you are not signed in yet, select the option Log in to iPhone, then enter your Apple ID and security password and press the button Log in.
- If you are using an older version of iOS, you may not need to perform this step.

Step 3. Select the iCloud entry
It is listed in the second section of the "Settings" menu.

Step 4. Choose which data to backup
Activate the sliders of the listed apps, for example Notes or Calendars, by moving them to the right (they will turn green). This way the corresponding data will be included in the backup.
Data from apps whose cursors are left blank will not be backed up

Step 5. Scroll down the menu and select the iCloud Backup option
It's located at the end of the "Apps that use iCloud" section.
Activate the cursor ICloud Backup by moving it to the right (it will turn green), if you have not already done so.

Step 6. Select the Back Up Now option
It is displayed at the bottom of the screen. At this point, wait for the backup to be complete.
For the iPhone to back up, the device must be connected to a Wi-Fi network

Step 7. Launch the Settings app again
It features a gray gear icon (⚙️). It is normally visible directly on the Home screen

Step 8. Scroll down the menu to select the General item
It is listed at the top of the menu and features a gear icon (⚙️).

Step 9. Scroll the new menu down and choose the Reset option
It is visible at the bottom of the page.

Step 10. Choose the Initialize content and settings item
It is one of the first options on the list.

Step 11. Enter the device passcode
This is the same PIN code you use to unlock your iPhone.
If prompted, also enter the code you set from the "Restrictions" menu

Step 12. Press the Erase iPhone button
In this way all the data contained in the device memory will be deleted as well as the customized configuration settings.

Step 13. Wait for the initialization procedure to finish
This step may take a few minutes to complete.
Method 2 of 2: Reset an iPhone

Step 1. Follow the instructions that will appear on the screen
The setup wizard will show you the steps to take to perform the initial setup of the device.

Step 2. Select the language you want to use
This is the language that the operating system will use to display menus and all other items in the graphical interface.

Step 3. Select a country
Choose the country in which you live and in which you will use the device.

Step 4. Choose the Wi-Fi network to connect to
The list of Wi-Fi networks found in the area will be displayed.
- If prompted, enter the password to access the network.
- Alternatively, you can choose to connect to iTunes via the computer after connecting the iPhone using the USB cable. In this case, choose the option Connect to iTunes.

Step 5. Press the Next button
It is located in the upper right corner of the screen.

Step 6. Configure Location Services
The device uses your location for Maps, Find My iPhnoe, and any other programs that require access to this information.
- Select the link Enable Location Services to allow apps to have access to the location of the device.
- Choose the option Disable Location Services to prevent apps from using your device's location.

Step 7. Create an access code
Enter a PIN code in the indicated field.
If you want to use a login password, instead of a 4 or 6-digit numeric code, select the item Code options displayed at the bottom of the screen.

Step 8. Re-enter the chosen code to verify its correctness

Step 9. Choose the Restore from iCloud Backup option
It is visible at the top of the configuration options list.

Step 10. Enter your apple ID and security password
Use the text fields indicated.

Step 11. Press the Next button
It is located in the upper right corner of the screen. You will be redirected to the terms and conditions page of Apple's agreement for the use of its products.
Read carefully the terms of the contract you are accepting

Step 12. Choose the Agree option
It is displayed in the lower right corner of the screen.

Step 13. Select a backup
Choose one of the most recent backups based on the date and time it was taken.