Warning!
NEVER RELOCK THE BOOTLOADER!
Unlocking the bootloader is pretty straightforward on Motorola phones. You need to unlock the bootloader in order to obtain root or install a custom ROM.
Keep in mind, this process will void your warranty. Also, you will lose all of your data on Internal Storage, so make sure to back up everything important before starting.
• Enable Developer Options on your device by going to System > About Phone > Tap on Build Number 5 times
• Open Developer options and enable "USB Debugging" and "OEM unlocking"
• On your PC, download the ADB Tools and extract it
• Also download and install the Motorola USB drivers
• Inside the extracted folder, Shift + Right Click, then select "Open command window here" or "Open PowerShell window here"
• Connect your device to the PC via USB, then in the Command prompt type adb devices
• Check your phone for a prompt and choose "Always allow"
Now you are ready to proceed.
• Boot your device in fastboot mode, either by doing adb reboot bootloader in CMD or by turning on the phone while holding Power + Volume Down
• Type fastboot oem get_unlock_data
• CMD will return 5 strings of characters, something like this:
(bootloader) 0A40040192024205#4C4D3556313230
(bootloader) 30373731363031303332323239#BD00
(bootloader) 8A672BA4746C2CE02328A2AC0C39F95
(bootloader) 1A3E5#1F53280002000000000000000
(bootloader) 0000000
What you need to do is convert it into one string, like this:
0A40040192024205#4C4D355631323030373731363031303332323239#BD008A672BA4746C2CE02328A2AC0C39F951A3E5#1F532800020000000000000000000000
• Copy that string and paste into the official Motorola website. You may need to login.
• Click on "Can my device be unlocked?", then, if it's possible, click on "Request unlock key". You will receive the key via email.
• Go back to CMD and type fastboot oem unlock [your key]. If confirmation is requested, retype the same command.
• Congratulations! Your device is now unlocked.