Recently I [had a problem][1] where my Nexus S phone would not upgrade to Jelly Bean. During the upgrade process I was getting an error message saying one of the files on my current system is corrupted, so the upgrade cannot be applied.

I knew clean install (instead of an upgrade) would fix the issue, but I had a really hard time finding clear information on how to do this. Most tutorials require you to download the new OS from untrusted sources (shady download sites) and assume your phone is rooted.

Thankfully as it turned out you can do this **using official Google software only** and you don't need to root your phone (you can - it doesn't matter).  

I post instructions for the method I used, as an answer below. This is also useful when you need to do a **true factory reset**. The "factory reset" function in Android only clears user data, leaving the OS as it was - useless if your operating system is damaged or if it was modified and you would like to bring it to an original, stock state. This solves the problem.

This instructions should work for any Nexus phone or tablet.

  [1]: http://android.stackexchange.com/questions/26474/jelly-bean-ota-update-failing-on-nexus-s-assert-failed