I do it all the time and just did on several flights/airlines in the past few weeks.
I put the gun in the smallest possible hard case with a padlock. Only you can have the key to this. I put the case inside a softside standard rollaround Samsonite and put a lock on it. This is a TSA approved tamper-evident lock. That keeps everybody honest. If they search my bag, I know it as soon as I get it.
You must declare your firearm and they give you a tag to put inside the case that contains the firearm. I keep all the old tags, and there are about 20 of them in there. I think it would be hard to prove any criminal intent if I forgot to declare it one day and the tags were present. Some airlines make their gate agents check to be sure it is unloaded. This puts all blame on them if it somehow becomes loaded after it leaves you. This will be on camera in most cases. I got pulled away from the boarding gate to come open my case one day in Texas. There were a couple neckties and a TSA agent present, and since the gate agent had checked my gun, there would have been some recourse if it had magically become loaded in my absence.
The ammo can be inside the same bag as the firearm, however, not inside the same container as the firearm. The ammo must be inside the OEM case, or one like it. I often use a plastic reloader's case for my ammo. They never look at the ammo, but they always ask.
Some airlines/TSA make you wait until your bag clears x-ray. If they want to check the gun, you hand them the key, they inspect with you present, and then re-lock.
And, this is exactly the way the law/TSA regs say it is supposed to be done.
Rarely, you will have a gate agent that is completely unfamiliar with the regs, or has their own interpretation of the rules. Remain calm and cool and ask for a supervisor if necessary. Usually they will just ask a more experienced agent what they need to do. It makes the day go faster.
I carry the .pdf file of the TSA regs on my laptop, just in case.......
TSA Linky 1[
TSA Linky 2