But I am worse off because I started off with 20k. I'm just not as badly off as I would have been had I not got a pay rise.
But it's the inflation that made you worse off. And it did that before either the pay increase or the tax on that pay increase.
Go back and look at your figures again:
You're paid 40k gross; take-home pay is 20k.
Inflation reduces the real value of your 20k take-home pay to 18k. That implies an inflation rate of 11.1%
Your employer gives you a 2k increase.
And now we come to the key point:
a 2k increase on an 40k salary is only a 5% increase. You would not expect a 5% increase in salary to compensate you for an 11.1% inflation rate.
If anybody's treating you unfairly here, it's actually your employer. Assuming the goods and services you produce for him are subject to the same inflation as the rest of the economy, they now command prices that are 11.1% higher than they were a year ago. But he's only paying you 5% more to produce them than he did a year ago. He's trousering the difference.
That may be unfair to your employer. Inflation isn't uniform across the economy, and perhaps the particular things you produce, and he sells, have only gone up by 5%, or maybe even less. But, for whatever reason, he only gave you a 5% increase when inflation was 11.1%. If you're worse off, the reason is that your pay is not keeping pace with inflation.