Error 21 is a disruption between your computer and gs.apple servers.
Check your firewall, security, etc.
Also check your hosts file by navigating to HDD/etc/hosts.plist and open it. Make sure the following is not there: #126.96.36.199 gs.apple.com
If it's there, remove it and save. Put your phone in DFU mode and restore.
I Had your problem to a 100% match. I took my phone to the Apple store yesterday and it actually turned out to be a bad battery connection. The connector was bent, making contact but screwing up the memory. My second battery replacement on my iPhone 4. $89.00 This absolutely and instantly fixed the problem. Please let me know if this helps ( or any of the ther 4 of you wiht this problem. I just created an account so I could answer your question.The Apple guy did tell em he had to put it in UDE mode whihc doesn't matter a bit if you're not there getting teh battery. I don't know what UDE mode is,. but I see it metnioned here a lot.To re-iterate, he said it would have done nothing for me on my own.
my iphone suddenly shut down. i tried to press on button and tried to reset it but it wont work. when i charged it the apple logo appeared i left it for at least two hours. when i came back the apple logo is still there. then i tried reseting it. the connecto to itunes appeared. i cannot restore it. itunes keeps saying an error occured(21). and one more thing. when i unplug in from charger or pc it turns off. as if it has no battery/battery is doesnt work. is it the batt or the ios? please help
I got the same Error 21 when trying to restore my iPhone 4 after a day out in moisty weather. The problem was indeed a bad battery contact, but I had to open my iPhone and disconnect the battery twice before it started working. Then the error disappeared and after two restore passes, my phone was finally restored. A backup on iCloud turned out useful and now music and all the apps are rolling in via iTunes. The screws are very small so You have to be careful if You decide to perform surgery on Your iPhone, I've got big clumsy fingers...