Error 4000 is an undocumented error code (at least publicly undocumented). It means that the connection between the phone and iTunes was interrupted in the middle of a sync or update activity. In the past this might have been caused by a flakey USB port, an antivirus or a firewall. However, there is a new cause of this error that is the result of a bug in iTunes for Windows that requires the phone not be locked during the update. So first check your antivirus and firewall (temporarily disable them), but if that doesn’t fix it there are three workarounds for the bug:
- Update over the air, by going to Settings/General/Software Update
- Downgrade iTunes to version 12.8 if you can find a copy - try https://apple.com/itunes
- Temporarily disable the screen lock passcode on the phone before updating using iTunes on Windows
Note that this error should only be a problem for updates; if you are restoring iOS rather than updating it should not occur.