This is from another thread I made in another forum, but I thought the Nexus 5 users that visit here might want to use it as well. I hope it serves you well...
This is a more descriptive (newbie friendly) guide, but it will essentially be using the methods as posted by Chainfire and described here:
Warning: Unlocking the boot loader on your Nexus 5 will factory reset it and wipe all of your data on it. Please back up any data you want to save. There are various methods you can use to do this, but this thread is meant to be a short and sweet guide on how to optionally root your Nexus 5, so these methods won't be covered here. Also, this is entirely a use-at-your-own-risk procedure. However, this method has worked well for me and countless others, so it should be relatively low risk.
This guide will be aimed more at users of Windows PCs (Windows 7 is what I used to do this), though similar methods using other OSs are available. For those, visit the link above.
Also, please read this guide in its entirety so you know what all is entailed before you start the process.
First you will need to download the Google USB driver for the Nexus 5 and the CF-Auto-Root tool kit. These are ZIP files and will need to be extracted to use them. (When referencing the names of these extracted ZIP files later in this guide, I will be assuming you chose to name the folders they were extracted to by their default names.)
Driver Download Page:
CF-Auto-Root Download Page: (Also, feel free to help support Chainfire and the great work that he does making these rooting tools and apps. He also has a Pro version of the SuperSU app for sale on the Google Play Store that you can optionally upgrade to. SuperSU will be installed on your Nexus 5 during this process, and is used to manage root privileges once you're up and running.)
Turn off your Nexus 5 then boot it in fastboot mode. To boot in fastboot mode hold down the volume down button and power button at the same time. It should boot up with a screen displaying our green Android friend lying down on his back with his service panel open.
When logged into Windows, connect your Nexus 5 in fastboot mode up to one of your computer's USB ports using its charging/data cable. Windows will try and install drivers for the Nexus 5, but will be unable to find any by default. Go into your Windows Device Manager in the Control Panel and find the device without drivers successfully installed. It will likely be listed as Android in Other Devices and have an exclamation mark in a yellow triangle on it. Right mouse click on this then click on Update Driver Software. Choose to browse your computer for driver software and direct it to the latest_usb_driver_windows folder where you extracted the driver software from Google. Also make sure that the check box Include subfolders... is checked. After it installs, it may erroneously list the Nexus 5 as being a Samsung device. That is alright however, as it shouldn't affect functionality.
Navigate to the CF-Auto-Root-hammerhead-hammerhead-nexus5 folder you extracted. Open this and then run root-windows.bat. When running, this should unlock the boot loader on your Nexus 5, root it, and install the SuperSU app. You'll know it's working if you see your Nexus 5 displaying various messages as well as showing a red Android figure. Wait for this process to finish and your Nexus 5 should boot back up, rooted and ready to go.
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License. AndroidCentral is an independent site
that is not affiliated with or endorsed by Google.