You are conflating the concepts of "marginal tax rate" and "effective tax rate."
In the US, we have a federal income tax and state income taxes, that are based on the idea of a "progressive tax," that is, the more you earn, the higher your marginal tax rate. The lowest tier of income is taxed at a low rate. The next higher tier of income is taxed at a slightly higher rate. At each step of income, the tax rate becomes higher. You proved this to yourself, when you found that the "last" $100 that you earned was taxed at 40%.
Now, if you calculate a weighted average of the tax rates paid on each step of your income, that is you effective tax rate.
So, while you paid 40% tax on the last or highest increment of your income, the average tax rate on all of the dollars you earned is 13.8%.