Let me start this by saying ten gallons of water per fish minimum. If you are going out and buying a couple of goldfish, they will grow too quickly with proper care to make it worthwhile to gradually move them to bigger tanks as they get bigger. Just start out with ten gallons per fish.
That said, there are situations where you might need to violate this rule. Raising a spawn of goldfish, for example, where you have lots of rapidly growing fish and will need to use multiple containers. In general the issue is dilution of waste products; you want to provide a stable clean environment for the fish, which means enough volume of water to sufficiently dilute the waste products between changes. This means that estimating how many fish you can keep in a given volume becomes a task of estimating how much waste they will put out.
My theory, which is loosely born out by a mathematical formula used in aquaculture, is that the waste output from a given fish is proportional to its surface area. Rather than its length or volume. What is the significance of this, if it is true? Two things:
I get this second point from another section that discusses the weight of a goldfish being proportional to its volume. And the volume is proportional to the cube of the fish's length. So we have three options: wastes proportional to (1) length, (2) area, or (3) mass/volume.
Why, intuitively, would I believe that the waste output of a goldfish is proportional to its surface area? My reasoning is that the waste output should be proportional to the amount of food metabolized, and that this, in turn, should be a function of the surface area of the digestive tract. Which I would think would grow proportionally with the fish and be proportional to the fish's surface area. Whew! This all may be a bit loopy, especially if the metabolic rate of the fish changes significantly with size.
Where does this leave us? Well, you can take the surface area of a fish as being roughly a function of the square of its length (assuming that the shape of the fish maintains about the same proportions as it grows). Using this fact, and saying that a four inch long fish needs ten gallons of water, we can work backwards to estimate how many fish of shorter length that same ten gallons could hold. The following table shows example figures for constant length, constant surface area (my favorite), and constant mass:
Remember that this is all speculation. As a closing point, note that the amount of surface area is as important as the volume of a container. Goldfish need a lot of oxygen and most of this comes from air-water exchange at the tank surface. In general, I would recommend favoring squat-ish tanks as opposed to tall ones.