one inch per gallon is only the coarsest of rules, a starting point, and obviously unfit in many situations.
Firstly, the amount of waste a fish will produce is primarily based upon the mass/volume of the fish. Consider that a 4 inch streamlined, torpedo-shaped rasbora will not be producing the same amount of waste as a rotund, beer-bellied 4 inch molly who is in a late-term pregnancy.
Secondly, the one inch per gallon rule becomes very silly in the limit of large fish. 20 one inch fish (like small tetras) can be very happy in a 20 gal tank, but obviously one 20 inch fish will not.
Thirdy, the species of fish enters into consideration. Fish from rapidly moving, highly oxygenated waters will require more water per fish than fish from slow moving stagnant ponds. This is where research becomes necessary. Also, some fish are very territorial. A 5 inch fish may claim much more than 5 gallons as its own personal space.
Finally, the fishkeeper's caretaking habits can change the balance as well. If you commit to increased water changes and caretaking, and you 'over-filter' your tank, you can get away with overstocking. But this is only recommended for the more experienced fishkeepers. Likewise, if you want to be lazier, you can plant your tank to help process the fishs' pollution but you should understock so that the pollution does not build up nearly as fast.
Many, many factors that "one inch per gallon" cannot take into account. It is just a starting point, and a good place to help newer fishkeepers not run out and purchase as many fish as can fit in a small tank.