It depends highly upon the use and tolerable weight of the rifle (barrel profile/thickness).
For a fighting rifle or ultra-light hunter, 16-20". For a hunting rifle, around 21-22". For an all-purpose practical rifle, maybe 22-23". For a heavy bench rifle, anywhere from 24 out to 30", or maybe even more for some sort of crazy mammoth gun. After 30" though, the barrel thickness required to make it stiff enough to hold outstanding accuracy becomes not worth the tradeoff in size and weight, for the small velocity gains (not to mention the cost in finding a barrel maker that will do over 30).
Personally, for long distance shooting, I'd prefer a 26" barrel or more. For a fighting rifle, 20" is good - a bit muzzle heavy (relative to the 16 or 18 inchers), but worth it to help tame the recoil & blast. For an all-purpose gun or hunter, I'd want right at 21.5 or 22" for a short cartridge like .308 win.