I used my Nexus 7, but this should work with all nexus devices...
!!! I am not responsible if you brick your device, or for anything else !!!
!!! This will delete all of your files on your device!!!
Step 1: Download the Image
Google has the images of all the nexus devices on their server.
Go to https://developers.google.com/android/nexus/images and download the image for your device.
Step 2: Download Some Android SDK Files
If you already have the android SDK files, skip this step.
Download the command needed to flash the image: https://drive.google.com/file/d/0BwU6LFnoV_gESG9JbGx1b05HckE/view?usp=sharing, and unzip it.
Step 3: Unzip the Image
If your image finished downloading, you should have a *.tgz file.
Unzip it using 7-zip (free program: http://www.7-zip.org/), and there should be a *.tar file inside. Unzip this file too.
Step 4: Copy the Commands
Go to the folder with the file flash-all.bat inside the folder you just unzipped.
Copy the files AdbWinApi.dll, AdbWinUsbApi.dll and fastboot.exe(platform-tools), and copy it to this folder.
Step 5: Boot Into Bootloader
If your device is powered on, power off your device.
Boot into the bootloader by pressing:
- Nexus 4: Volume Down button and the Power button
- Nexus 5: Volume Down and Volume Up buttons
- Nexus 7: Volume Down button and the Power button
- Nexus 10: Power, Volume Up, and Volume Down buttons
Step 6: Flash the Image
If your bootloader is locked, press shift and right click on an empty space in the folder, and click open command window here. In the cmd window, type fastboot oem unlock. !! This may void your warranty !!
Execute flash-all.bat, and wait. Your device reboots when finished.
Step 7: Optional: Lock Your Bootloader
Boot your device into bootloader.
In the cmd window, type fastboot oem lock.