Fed law sez min 18" bbl length and 26" overall length. Bbl length is measured by dropping a rod down the bbl against the closed bolt and marking at muzzle end. Overall is measured with stock extended. It is best to have some "extra" as the guy measuring it in the field might be off a 1/4" or so. if you permanently attach a muzzle device, the device is measured as part of the bbl.
That's Fed law, state and local laws vary MI and Kali have some weird laws concerning bbl and overall length.