This is a pretty common question that is asked all of the time, and the answers are often horrible. People will pop-up claiming to be subject matter experts on the topic, and they will start quoting ridiculous numbers that just are not even close to being right.
Short Answer: You should change out your barrel after it has been used/abused so much that the accuracy starts falling off.
In the vast majority of cases, this will be after the lifetime of the person that bought or built the rifle.
Long Answer: There is no answer that can be applied to every case. The life of a barrel depends on many factors, including the following:
Barrel Length – A shorter barrel, like a pistol barrel, will, generally, need to be replaced sooner than a longer barrel assuming they are treated and used the same way.
Metal – The metal used in the barrel will certainly have an impact on the wear. For example, a chrome moly vanadium barrel (used for machine guns) will outlast a chrome moly barrel with a chrome lining, and they will both outlast a stainless steel barrel.
Manufacturing Process – There are many ways to create a barrel, and to make it more accurate and longer lasting. Cold hammer forged barrels, for example, are usually more accurate and last longer than other processes. While nothing is absolute, this is a generalization.
Treatments – Chrome lining, nitriding/meloniting, etc, will impact the barrel life. Chrome linings, for example, will provide a much longer barrel life.
Ammunition – Higher pressure, higher velocity ammo will shorten the life of the barrel, as will the different metal types of the bullets. Obviously, harder metal bullets will have a negative impact on the barrel life as will the larger bearing surfaces of some bullets.
Heat – by this, I mean the fire rates and how much the barrel is heated up when used. For example, if somebody is doing magazine dumps and shooting as fast as they can over and over, that impacts the barrel life in a very negative way. Hot metal gets softer, and the friction of the bullet traveling its length causes greater wear.
By far, the largest factor when looking at barrel life is the impact of heat which is a direct result of how the rifle is used. If the rifle is shot in properly and not abused, it should last about forever.
As to a number of rounds? Well, since none of use can really count that high, don’t even worry about the number of rounds. Those of use that shot on a regular basis and buy 5,000 or more rounds at a time will be concerned with numbers, but again, the answer is that the barrel needs to be replaced when its accuracy starts to degrade.
There is no magic number for any particular barrel.