A factory restore erases the information and settings on your iPhone, iPad, or iPod and installs the latest version of iOS, iPadOS, or iPod software.
Get your device ready
Make sure your Mac or PC is updated. If you're using iTunes, make sure you have the latest version. If you can't access a computer and your device still works, you can erase and restore your device without a computer.
If you want to save the information on your iPhone, iPad, or iPod, make a backup.
Go to Settings > [your name] > iCloud, tap Find My iPhone, then turn it off. For an unresponsive device or one that won't turn on, learn what to do. If you forgot your passcode, get help.
Restore your device to factory settings
On a Mac with macOS Catalina 10.15, open Finder. On a Mac with macOS Mojave 10.14 or earlier, or on a PC, open iTunes.
Connect your device to your computer.
If a message asks for your device passcode or to Trust This Computer, follow the onscreen steps. If you forgot your passcode, get help.
Select your device when it appears on your computer. For an unresponsive device or one that won't turn on, learn what to do. Or get help if your device doesn't appear on your computer.
Click Restore [device]. If you're signed into Find My, you need to sign out before you can click Restore.
Click Restore again to confirm. Your computer erases your device and installs the latest iOS, iPadOS, or iPod software.
After your device restores to factory settings, it restarts. Now you can set it up as new.
Original Source: https://support.apple.com/en-us/HT201252