Before you start, make sure your device is backed up. Messing around with SIM carrier stuff can be risky, so you never know. It might explode. Not our fault.
1: Dial the Secret Number
Launch the phone dialer and enter *#27663368378#, but DO NOT press call. The phone will automatically take you to the ServiceMode menu.
2: If That Code Fails
In case *#27663368378# doesn't do anything on your model, try entering *#0011# instead.
This will take you to the basic information section of ServiceMode.
From there, press the Menu button on your device and then the Back key in the menu—not your phone's menu key. Tap on the Menu button again, but this time press Key Input.
Enter 1 and press OK.
3: Select Debug Screen
You should now be at UMTS MAIN MENU in ServiceMode. Select  DEBUG SCREEN.
4: Select Phone Control
At the DEBUG SCREEN, you'll see six options. Select  PHONE CONTROL.
5: Select Network Lock
From the Phone Control screen, select  NETWORK LOCK.
6: Select Perso Off
On the next page, you should see three options. Select  PERSO SHA256 OFF.
7: Go Back to Main Menu
Now, head back to the Main Menu by tapping on the Menu button and then the Back key (from the menu).
8: Select Common
On the UMTS MAIN MENU, select  COMMON.
9: Select NV Rebuild
Now, tap on  NV REBUILD.
10: Restore Back Up & Reboot
Finally, the phone will notify you that a Golden-Backup exists. Select  Restore Back-up.
Your Galaxy S4 will now reboot automatically, which might take a few minutes. Once it's back on, the network will be unlocked, allowing you to use any SIM card that will work in your model phone.