Okay, so you're rooted and need to return your Nexus 5 to its stock firmware. Whether it's because you need to send your phone in to the manufacturer to fix a defect or you just want to use the device's over-the-air updating feature, unrooting and returning your Nexus 5 back to its fresh-out-of-the-box state is a fairly simple process with the right tools.
Plug your Nexus 5 into your Windows PC using any USB cable. Make sure the cable you're using has no visible damage to either connector and that it plugs in firmly to your phone, as an accidental disconnect during this procedure could lead to a bricked device.
In order to get access to this setting, we'll need to unlock the Developer Options menu. To do that, head to Settings, then About Phone. Scroll down to the bottom of this list and tap Build Number 7 times in rapid succession.
Note: Take this opportunity to jot down your Build Number, it will come in handy later.
From here, back out to the main Settings page and tap Developer Options. Tick the box next to USB Debugging, then select OK from the dialog that appears next.
Once the download has finished, install by double-clicking the file in your browser's download folder. Click Run on the following window.
Follow the prompts for installation, allowing the toolkit to download additional files when it asks.
As the installation process finishes on your PC, a dialog will appear on your Nexus 5 asking you to allow USB debugging access from the computer you're connected to. Tick the box next to Always allow from this computer and press OK.
When the installation is complete on your PC, you will be prompted to enter your phone's Model and Android Build. Enter Nexus 5 as the model, and refer to the build number you jotted down in Step 2 for the Android Build.
Next, click the button labeled Full Driver Installation Guide - Automatic + Manual near the top-right of the toolkit's main screen.
Follow the instructions provided by the toolkit to install the proper device drivers. On the "Step 3" tab in the dialog box that appears, take note of the Recommended Solution it provides and install the corresponding set of drivers.
As you probably remember, the process of unlocking your Nexus 5 deletes all of your phone's apps and data. The same applies when re-locking and returning to stock.
There are several methods available to back up your data, but most won't be able to restore anything without root or a custom recovery. The best option to back up your music, photos, videos, and other data is to copy them to your PC temporarily using Windows Explorer. When you have returned to stock, you can then copy these files back to your phone.
For backing up apps, however, there is an automated option provided by the Nexus Root Toolkit. Simply click Backup from the toolkit's main menu, then select Create Android Backup File on the following screen.
Follow the toolkit's instructions through the backup process. Be sure to note the save location of the backup file so that you can find it when it comes time to restore.
Before proceeding, remember that THIS PROCEDURE WILL DELETE ALL APPS AND DATA FROM YOUR PHONE.
From the main menu of the toolkit, select Flash Stock + Unroot.
Press OK to continue, and on the following screen, make sure Automatically download + extract the factory image selected above for me is selected.
Click OK, then follow the instructions to flash the factory images. DO NOT DISCONNECT THE USB CABLE DURING THIS PROCESS.
Now that you've flashed the stock firmware, all of your previous settings have been reset. This includes the USB Debugging option we enabled earlier, so refer back to Step 2 of this guide to enable it once again.
The dialog on your Nexus 5 asking to allow your computer to connect should appear right away this time. Tick Always allow from this computer and select OK again.
Not only will this part of the process put the bootloader back into its original state, but it will also destroy any evidence of the phone having been modified in the first place. This is important if you are returning your phone to the manufacturer or your wireless carrier for warranty purposes.
From the main menu of the toolkit, select OEM Lock, then OK from the following prompt.
This process will automatically reboot your phone several times, so be patient.
At this point, it's safe to go ahead and restore any backups you've made. If you copied any data to your PC, you can now copy that back to your Nexus 5.
To restore any apps you backed up with the toolkit, click Restore from the main menu, then Restore Android Backup file from the next screen.
Follow the toolkit's instruction to complete the process.
You should now be holding a completely stock Nexus 5. Your phone is now ready to be sent back to the manufacturer or carrier if need be. Otherwise, enjoy your fresh-out-of-the-box device.
New Nexus 5 image via Phandroid