Inflation is generally defined by looking at the relative change (that is, current divided by some reference amount) of the Consumer Price Index. The CPI is a weighted average of a basket of goods and services. It can be thought of as the "exchange rate" between dollars and a "commodity" that consists of this collection of goods (I put "commodity" in quotes because it is a compound value made up of all of these goods and services, and not all of them are commodities). The price of gold is the "exchange rate" between dollars and gold. The purchasing power of gold is the "exchange rate" between gold and the CPI. The value of gold to you is the "exchange rate" between gold and what you actually want. These four numbers are distinct, and can vary independently. Your purchasing patterns aren't going to be exactly equal to the goods and services that make up the CPI, so the value of gold to you will be different from what an economist would calculate its purchasing power to be. And the price of gold varies separate from the CPI.
A key point here is that inflation is often spoken as an across-the-board increase in prices, but the reality is that the marketplace involves a wide variety of prices that do not fluctuate in unison. When economists want to measure "inflation", they have to collapse all of those fluctuations down to one number. This number reflects some "average" price increase, but there is no single objective "right way" to average the increases, let alone an average that reflects every price increase. The price of gold can shoot up while other prices remain stagnant, or vice versa.
Gold is correlated with inflation, and over long time periods is somewhat stable. While currency has a general downward trend in value, gold has roughly the same probability to go up as it does to go down. While inflation is a relatively consistent, expected decrease in the value of currency, commodity prices are based on discounted expected future value, and thus do generally avoid consistent drops in prices, and so provide safety from inflation in some sense.
But while gold is a good hedge against inflation in expectation value, it's not a good hedge in terms of volatility. Here is a chart of gold prices for the last 103 years. Over the entire period, there's been a significant increase, even adjusted for inflation. But on shorter time scales, that's not always the case. From 1934 to 1970, for instance, was a 36 years period of almost constant decrease in price, and 1980 to 2001 was a 21 period of decrease. Those two periods alone make up 57 years out of the 103 years shown, so gold prices were falling for more than half the time. While over the whole period, prices increased by a factor of 2.76, the 5-month period from Sep 1970 to Feb 1980 saw the price jump by a factor of 9. That means that if just 5 months out of 103 years were ignored, the overall change goes increasing by a factor of 2.76 to decreasing by a factor of 3.26.
Note that buying gold is, in some sense, an "anti-investment". Your money is going towards having bricks of metal sit around rather than actually go towards something economically productive. Not only do you have opportunity costs (while buying gold would have gotten you a 163% increase in capital over the last 100 years, stocks would have gotten you over 60 000%, and with less volatility) you are paying direct costs such as storage fees.