Step 1, download the appropriate factory image at the right side of this webpage.
Step 2, unzip it and locate flash-all.sh file.
Step 3, restart your Android phone into fastboot mode. You can connect your Nexus and run the following command from a computer:
$ adb reboot bootloader
or use key-combos found here.
Step 4, while Nexus is connected to the computer and booted up in fastboot mode, execute flash-all.sh file from your computer as root. You need fastboot utility. If you have Android Studio installed, you already have it. Otherwise, you could download the command line SDK from here. Make sure to run with root privilege!
$ sudo ./flash-all.sh
That's it! It will automatically carry out some tasks and reboots, and restore your phone into factory image.