"Trying to restore my iPhone that is stuck on the Apple logo. Keep getting error 21. What is this and how can I fix it?"
- from Apple Community
Have you ever met the "unknown error 21" during the process of restoring an iPhone? Usually, the unknown error 21 occurs when you are trying to restore, update, or download with iTunes, and iTunes will pop up a window reminding you that "The iPhone could not be restored. An unknown error occurred (21)." Please don't worry, you can easily fix this iTunes error 21 or iPhone error 21 with the solutions in this post without hassle.

To begin, it's important to understand what iPhone error 21 is. Also known as iTunes error 21, this issue occurs when you're attempting to update or restore your iPhone, iPad, or iPod. Specifically, the error happens when the authentication process is interrupted while iTunes is downloading and verifying the firmware files.
You may be wondering why iPhone or iTunes error 21 appears when restoring your device. Let's dive into that next. Below are some possible reasons behind the occurrence of iPhone error 21 or iTunes error 21.
If you'd like to fix iPhone error 21, you can try the common troubleshooting methods below.
Among all the factors that can lead to Error 21, USB connection issues are the most common. If the cable is worn out, the connection is poor, or non-certified accessories are used, iTunes may be forced to interrupt when transferring system files. You can try the following steps:

Just like rebooting your computer, restarting iTunes can also help resolve the error. iTunes isn't perfect and can often behave unpredictably. In such cases, a simple restart of iTunes might be the most effective solution.
Start by disconnecting your iOS device, closing iTunes, and then reopening it. Reconnect your iOS device to your Mac or Windows PC, and try the update or restore process again.
If that works, it may have been a minor computer issue. If not, keep reading for the next solution.
An outdated version of iTunes may not be compatible with the latest iOS firmware, which can easily trigger iPhone Error 21 during verification. You can update iTunes to the latest version to resolve this issue.
Just go to "Help" > "Check for Update" on the left top of the iTunes window to upgrade iTunes to the latest version. Or you can also directly download the latest iTunes on your computer from Apple's official website.

Sometimes the security software, like anti-virus, can interrupt the connection between the iOS device and the Apple server. So, you can check the third-party security software on your computer to keep it for some time. And you can enable it again when you have successfully restored your iPhone with iTunes.

If you connect your iPhone or iPad to the computer while also plugging in other devices, especially smartphones or storage drives, those devices may cause conflicts that prevent iTunes from detecting your iPhone or iPad. To resolve this issue, it's best to unplug any unnecessary USB devices.
If the hosts file has been modified, it may prevent iTunes from communicating with Apple's official servers, resulting in iPhone Error 21.
Check the Host File on Mac:
Step 1. Open the "Applications" folder and go to the "Utilities" folder.
Step 2. Launch "Terminal" and type the following command: "sudo nano /private/etc/hosts".
Step 3. If prompted for your password, enter your Mac's password and press "Return".
Step 4. The terminal will now display the host file. Scroll down to find any entries that include "gs.apple.com".
Step 5. After deleting the line, check if the error persists by attempting to update or restore your device in iTunes.

Check the Host File on Windows:
Step 1. Press the "Windows" Key + "R" to open "Run", then type: "C:\Windows\System32\drivers\etc\hosts".
Step 2. Your computer may prompt you to choose how to open the file. Select "Notepad".
Step 3. Browse through the lines, looking for any entries that contain "gs.apple.com". If you don't find this entry, there's no communication blockage.
Step 4. If the entry exists, back up the file by saving a copy, then delete the entire line containing "gs.apple.com".
Step 5. After deleting the line, check if Error 21 still occurs by attempting to update or restore your device in iTunes.

You can try putting your iPhone into DFU mode to resolve iPhone Error 21. However, please note that this method will erase all data and information. Therefore, it's best to back up your iPhone before proceeding.
Here is how to do it:
Step 1. Plug your iPhone into your computer and open iTunes.
Step 2. Put your iPhone into DFU mode. Once your device is in DFU (Device Firmware Update) mode, you'll see a pop-up message in iTunes. Click "OK" to continue.

Step 3. Go to the "Summary" tab in iTunes and click "Restore". After the restoration, your device will restart.
Checking the sensor might sound complicated and requires caution, but a loose sensor cable can indeed cause Error 21. In this process, you'll need basic tools like screwdrivers, tweezers, and more to open the iPhone's rear panel. To inspect the sensor cable, first unscrew the battery to disconnect the power. Then, carefully pull out the cable, clean it, tighten it, and reassemble everything in order.
If none of the above solutions work, or if you want to avoid data loss altogether, using a professional iOS repair tool is the safest option. iOS System Recovery is specifically designed for iOS system errors and is excellent at fixing various iTunes or iPhone issues. It can repair multiple system problems, including Error 21, while preserving your data in Standard Mode.
Key features of iOS System Recovery:
Here is how to fix iPhone error 21 with iOS System Recovery:
01Download the right version of the program and launch it after installation, and connect your iPhone to the computer with a USB cable. When the program detects your device, switch to "More tool" > "iOS System Recovery" of the program.

02Then this tool will automatically detect your iPhone's possible problems and show them, like iPhone Error 21, iTunes Error 27, screenshot not working, stuck at Apple logo, Recovery mode, etc. Please hit the "Start" button to go on.

03Then please confirm your iPhone information. If it is right, please click the "Repair" button to fix iPhone or iTunes error 21 right now; if not, select the right one and hit the "Repair" option to start the fixing process. This program will download and install the latest firmware on your device after detecting your current iOS version.

Wait for a while, your iPhone error 21 issue will be fixed with the program. And you can start to connect your device to iTunes to restore or update your iPhone again.
Although iPhone error 21 can be frustrating, in most cases, it doesn't mean your hardware is beyond repair. If the usual methods don't work, or if you want a one-time, safe fix, iOS System Recovery is highly recommended as the ultimate solution. It can solve not only iPhone error 21 or iTunes error 21 but also many other iOS-related issues, all without data loss. Install it on your computer now!
Related Articles:
9 Useful Ways to Fix Unable to Clear History After iOS 26 Update
How to Fix iPhone Stuck on Connect to iTunes? Complete Fix Guide 2026
[Solved] How to Fix iPhone Taking Forever to Update iOS 18/26?