What krocus says is true, but incomplete. The powder is usually burned in the first few inches, I say few, because it depends on powder type and cartridge capacity. Between the 308 and 30-06 there isn't a whole lot of difference, but a 308 vs 458 Win Mag, there's a lot more powder to burn.
In addition, the velocity comes not only from the powder burn rate, but from the pressure curve as well. If you read the data coming out from companies like Hornady, you'll see how their newer smaller cartridges are matching older larger cases in velocity, in 4" shorter barrels.
One cae in point is the 375 Ruger. It matches or exceeds the 375 H&H when the Ruger is fired from a 20" barrel, vs the 24" std for the 375 H&H. When the Ruger round is shot from a 24" barrel, it bests it by 100-200fps. With a flattened pressure spike (or curve) in the Hornady load, the pressure is building longer, thus accelerating the bullet longer.
In normal loads, once the pressure has spiked, the bullet is proceeding down the barrel from momentum only, at this time friction in the barrel has a greater effect on the bullet. In a longer curve, the bullet is being continually pushed until the new longer spike has stopped. Then it too is using momentum, but friction has less time to affect the bullet, or slow it down, because it's exiting the barrel with less momentum time than the regular loads give it.
Purely as an example, if you have a 22" barrel, and the powder burns from a regular load in 6", and has peaked it's pressure spike, at say, 12" of the barrel, there is actually 10" of barrel left for friction to make a difference.
Now in a load like Hornady's, the powder may burn at 6", but the pressure spike isn't over till 15" of the barrel, then that leaves only 7" of barrel left for friction to work on. That could mean 100-200fps difference.
That is the reason there are faster burn rate powders for pistols and slower rate powders for rifles. it gives the pressure time to work on the bullet.