First, any gun that’s been out in the rain or snow should be thoroughly cleaned and lightly lubricated inside and out at the end of the day to avoid moisture-related problems. If conditions were good, you should still wipe down the metal exterior parts of any gun after you’ve shot it or even handled it, because this protects the metal from the acid in your fingerprint oils, among other substances that can damage the metal over time. But when it comes to breaking the gun down and cleaning the internal parts, including the barrel, the “how often” question is entirely dependent on what kind of gun we’re talking about.
It’s a good idea to give your handgun a quick wipe-down and run a few patches through the bore after a day of shooting. Make sure everything has a very thin layer of lubrication to avoid any rust. If you shoot your handgun regularly, you shouldn’t have any trouble going a few range sessions in between serious deep cleanings. However, if you’re not likely to be shooting the gun again for months, go ahead and give it a real breakdown and clean after your trip to the range. This especially applies to your concealed-carry handgun. Dirty guns are more prone to jams, and that’s the last chance you want to take with a gun you’ve bet your life on.
“Shotguns need to be cleaned?” is kind of an old tongue-in-cheek joke, because a reliable pump- or break-action shotgun is likely to keep running for years without a good cleaning. That doesn’t mean rust won’t be slowly building somewhere internally, though. Definitely make sure the entire gun is cleaned and lubricated if it’s been exposed to rain or snow, but if you’ve been out at the range in good conditions, a quick wipe-down of the metal parts and a lubricated Bore Snake ran down the barrel once or twice is more than sufficient until the next outing. Give it a deep clean once a year and you should be fine. If it’s an inertia-operated semi-auto, the same applies.
Gas-operated semi-automatics need cleaned more frequently because the gas system gets gunked up after a few hundred rounds (this is the trade-off for the gun’s reduced felt recoil). I clean my shotgun’s gas system after every outing so I know it’s always in ready-to-go condition.
Rifles are trickier. Some rifle barrels shoot best when they’re cleaned every 10 shots or even more frequently. On the other hand, many rifles shoot better or more consistently with a dirty barrel, and their owners might go hundreds of shots between cleanings. If you are a competitor who demands the best possible accuracy out of your rifle, you will probably keep track of how many shots have been through the barrel since the last cleaning, and you’ll soon identify the magic interval where your gun shoots best. Some shooters like to thoroughly clean their barrel, then fire a specific number of “fouling shots” before a competition starts to get into the slightly-dirty range their gun likes.
As a general rule, you’ll know your barrel needs to be cleaned when your groups start opening up, you start losing velocity, or point of impact starts drifting for no other obvious reason.
As for the rest of the rifle, you should wipe down the bolt and the exterior metal parts with an oiled rag after every outing. My hunting rifles get this treatment after every range day or trip to the field, and then they get a deep cleaning at the end of the season before they’re put up in the safe for months. That’s probably not necessary, considering I only fire a handful of shots each hunting season, but I don’t like the idea of a fouled and dirty gun stored for long stretches of time.
Semi-automatic rifles like the AR-15 tend to get dirtier more quickly than bolt-action rifles, because they often see higher round counts and because of the way their action works. Like semi-auto shotguns, they benefit from a gas system that’s cleaned regularly. It’s a good idea to thoroughly clean your AR-15 after a couple of high-volume range sessions or a couple of months of occasional use, whichever comes first.