Install Kies on your computer, connect your phone and make sure that all the drivers installed correctly. Download Odin to your PC. Extract tar file from the ROM. Put the phone into download mode (vol. down+home+power buttons), start odin, connect the phone via USB. Choose continue on the phone, make sure that only two boxes are checked in odin - Auto Reboot and F.Reset Time. Choose PDA button in Odin and select tar file you extracted before. Choose START button. The phone will reboot after the flash. Done.
Use this method only with stock firmwares. Methods are different for custom ROMs.