Important note: Restoring your phone to factory settings will clear apps, contacts, SMS and other data in the phone; they can't be restored after the operation. Be sure to back up any important data beforehand, including chat records of third-party applications such as WhatsApp.
To restore your phone to factory settings, go to Settings> System> Reset Options> Erase all Data.
Note:
If your phone is set with a lock screen password or you're logged in with your Google account, you'll need to verify your lock screen/ Google account password before resetting your phone. Ensure you have a stable network connection for this. After restoring, enter the password, and set the phone.