Generally, rooting a phone is complicated and voids the warranty, but it is not the case if you own a Xiaomi device.
You have official root support for its devices, and enabling it on the Mi 4 couldn’t be any easier. In fact, you don’t even have to flash a custom recovery for this.
How to root the Xiaomi Mi 4
First, go to this thread at the MIUI Vietnam Forums and download the zip file. (from post #22)
Copy it to the main folder of the Mi 4.
Open the Updater App, and tap on the menu.
Choose the option which says “Update package to install”, and select the file you downloaded
Once the process is done, you will be prompted to reboot the phone.
How to enable Root access on the Xiaomi Mi 4
Once you have completed the above steps, open the Security app, and navigate to Permissions > Root Access.
You will be able to enable root for any apps which are listed at this screen.
Tested with the Global Stable ROM MIUI v126.96.36.199 (KXDMICF).
Updated for the MIUI v188.8.131.52 (KXDMICF) Global Stable ROM