First of all, most guns have two barrel diameters.
The first is bore diameter -- that's the size of the hole drilled in the barrel.
The second is groove diameter. That's the distance from the bottom of one groove, across the center of the bore to the bottom of the opposite groove.
For example, the bore diameter of a .30 caliber barrel is nominally 0.3000 inches. The grooves are nominally 0.04 inches deep. So the groove diameter would be 0.308 inches.
Some guns are named for bore diameter, others for groove diameter. A good example is the .30-06 versus the .308 Winchester. Both are .30 caliber, but one is named for bore diameter, the other for groove diameter.
Then there are tolerances -- typically a gun barrel is held to about 0.001". So barrels of identical calibers can vary a bit.
And finally, there are names which may or may not have any relationship to bore diameter. For example, the .38 Special has a nominal groove diameter of .357". The .380 ACP has a nominal groove diameter of .355". But the .38 Winchester Central Fire (.38-40) is closer to .40 caliber than to .38.