What does unlocking the bootloader do? My understanding is that a boot loader is like a BIOS in a PC, which will help a device to load the OS correctly. 

When I unlock the bootloader in an Android device, does this modify the complete bootloader itself? In other words, will this install a completely different bootloader compatible with the device? Or is it just a slight modification in the existing bootloader?
After some research, I finally got some details.

Unlocking a bootloader will generally not change the bootloader of a device.
The locked bootloader somehow ensures that the device should boot up with the OS that is shipped originally with the device or updated by the vendor officially.

Locked bootloader puts this as a security measure so that it can prevent the users
from installing custom ROM's. When the bootloader is unlocked it will simply provide the booting instructions to the device without checking for the stock ROM
on the device. The device will boot with the ROM present in /boot and /system partitions and thus unlocking a bootloader is an essential step if one want to install custom ROM. 

Thus overall, locking a bootloader is just an extra built-in security check and 
unlocking will just remove this check but will not modify the entire bootloader 
of your device.