I don’t normally do gun threads as the topic is quite volatile, though I will say it’s probably the number one question I get asked when people find out I backpack, followed by questions asking me what I eat.
I do not and have never carried while backpacking. I assume that you are worried about other people other than animals, but for animals I will say this.
I was false charged by a Black Bear in GSMNP about a mile north of Derrick Knob in ~2010 and I will say that it all happened so fast that it wouldn’t have mattered if I had a gun on my hip or bear spray available, I wouldn’t have been able to unholster and/or aim before the bear would have been on top of me.
I have run across a few people on the trail that I have felt uncomfortable around, and I have just kept going. One time on the AT, I was going to stay in a shelter (which is unusual for me) and there was an individual inside that I felt funny about, so I decided to keep going and did 3-4 more miles that night before camping. Ironically, the fact that he had a gun and a large knife only added to my discomfort.
I stand by the fact that the most dangerous part of backpacking is driving to the trailhead.