The gun must be unloaded and packed in a locked, hard-sided gun case. Don't cheap out on the case; it will be worth it in the long run.
The detachable magazine, if the gun has one, must be removed and placed separately in the locked case.
Ammunition must remain in the original packaging or be placed in a cardboard, wood, or metal box. Small arms ammo smaller than .75 caliber for a rifle or pistol, and any shotgun shell, can be packed inside the firearms case. Anything bigger has to be locked in a separate case.
You must declare the gun at the airline ticket counter and check it with other checked luggage. When you do this, TSA agents will examine the gun and you will fill out a declaration form. It's the same process if the weapon is a handgun, rifle, air gun, or a knife. If the gun case is too large to fit in luggage, be sure to ask what the airline's retrieval process is at your destination, since firearms don't get put on the luggage carousel with everything else when they're packed on their own.