In order to understand what makes a shoe fit the way that it does, you have to have some understanding of how the shoe is made.
Shoes are constructed on an object called a “Last”. The Last is a form made of wood or plastic that the leather of the shoe is wrapped over to create the shape of the shoe upper.
Each manufacturer of shoes has their own set of lasts, in each size and last design that they make. So not only can shoe fit vary from brand to brand, in the same size, but it can vary within a brand depending on which Last design was used for a given style of shoe. Manufacturers also update their Lasts from time to time, so a newer version of the same style shoe may fit differently than a previous one.
It is also very important to note that Lasts are measured in a multitude of ways, not just length and width like a foot.
In reality a shoe is never made to fit a foot from heel to toe, it is made to fit your foot from heel to ball (at the base of your large toe). A formula is used to determine the minimum length of the shoe past that point, but this allows the designer to define different toe shapes without worrying about shoe length.
Next time you are in a shoe store or shoe department, look at the Brannock device used to measure your foot. There is a little piece that slides up next to the ball of your foot that actually tells your shoe size, not the length of your foot (which is also measured by a Brannock device).
Another interesting thing to note is that the width of a shoe is not determined by the width of your foot at the ball of your feet, it is measured in the girth of the Last in the area of the instep and ball of the foot.
The width of your foot varies constantly, unless it is at rest. And, it can form to different shapes, to some degree. This allows for different Lasts to have different widths at the instep/ ball, while still maintaining the same width sizing. As long as the girth is the same (narrower, but with a higher instep, for example) the width measurement is the same.
The phrase “fits like a glove” is not applicable here. There are only 5 sizes of gloves (XS, S, M, L, XL), but there are about 20 standard shoe sizes, and it is still hard to get a perfect fit (without going bespoke). The best you can hope for is a comfortable fit.
This is why it is so important to try shoes on before you buy them, rather than buying online. However, many online shoe stores have great return policies just for this reason.
If you find a shoe that fits you very well, try to find out the manufacturers Last model. This will allow you to buy shoes other shoes built on that Last. You can also look for a similar Last shape from another manufacturer to get a good fit. Most of the better quality shoe manufacturers either publish, or can tell you, which Last a given shoe model was built on.