It depends on a lot of factors.
The first of which is the report (sound) of the weapon. A .50 BMG can be heard from much farther away than a .22 LR.
Also, you must take into account the terrain over which the sound will travel. If you fire a gun on one side of a hill, it will be much harder to hear it on the opposite side than if there were no terrain in between the two.
You must also take into account the weather. Sound travels much farther in colder air than in warmer air due to the density. When air becomes colder, it begins to condense making it thicker and better able to transmit sound. Conversely, when air becomes warmer, the air molecules spread out and do not carry the sound as well.
One of the final factors is the design of the weapon. Many weapons come with muzzle breaks, compensators, suppressors, etc. Each of these can, and does, have an effect on how the sound comes out of the barrel. Silencers (supressors) are self explanatory. They help to muffle the sound of the explosion before it comes out of the barrel. Muzzle breaks and compensators often times redirect the energy of the blast and therefore the sound as well. If it were to redirect it in a direction away from the listener, then te sound could not be heard from far away.
Overall, the sound of a gunshot an be heard from a long way off, but the sound will not travel forever. In short, it really just depends. On a cool night, in the open outdoors, with no terrain in between the shooter and listener, then it could travel for miles.
(BTW, the above is a "google" answer.)