Recent economic data shows that inflation rates are beginning to rise slightly, proving that inflation is more resilient than many experts first thought. Investors should keep inflation in mind and position their portfolios accordingly.

How? Some companies can not only deal with inflation but thrive on it. Two great examples are Visa (V -0.23%) and Mastercard (MA 0.07%). These two leading payment networks can protect your portfolio from inflation.

I'll show you how these two companies can do it below.

Why inflation doesn't hurt Visa or Mastercard

First, it's essential to understand what inflation is and why it can be harmful. Inflation is the rise of prices. It generally happens in two ways. Prices rise when there is more demand for something than available supply, called demand-pull inflation.

On the other hand, cost-push inflation happens when the cost of making something increases, and producers raise prices to compensate. Inflation is normal, but too much can harm consumers, especially when it outpaces wage growth. In other words, prices rise faster than incomes. When that happens, consumers' buying power and quality of life decline.

Visa and Mastercard are payment networks that pass information between merchants where you swipe your payment card and the banks that hold your money or credit. Payment networks are like toll booths -- Visa and Mastercard collect a small fee, a percentage of each transaction that passes through the network.

If prices rise, the fees rise, because it's a percentage of the transaction value. So, generally speaking, Visa and Mastercard might be considered inflation-proof.

Two-pronged growth

The only thing that has slowed Visa and Mastercard's remarkable growth since the early 2000s has been the occasional crisis that has muted consumer spending. Below, you can see the dip that occurred when the economy slowed to a virtual standstill amid COVID-19 lockdowns.

V Revenue (TTM) Chart

V Revenue (TTM) data by YCharts

Over the long term, Visa and Mastercard will enjoy a two-pronged tailwind of steady, inflation-driven revenue growth and a broader shift away from cash as a payment method. Visa's transaction count has almost quadrupled from 58 billion in 2013 to 212 billion in 2023. Mastercard has done even better, growing from 18 billion to 171 billion.

The global market for digital payments is projected to grow by 15% annually and reach over $24 trillion by 2030. It seems realistic that Visa and Mastercard could each continue growing revenue at a pace near double digits for years to come.

Can these stocks still rock your portfolio?

Both Visa and Mastercard are poised to generate great long-term investment returns as long as they keep growing revenue. Here is how. Not only is double-digit revenue growth a high floor for returns, but Visa and Mastercard are also remarkably profitable. These companies generate a ton of cash flow from their respective revenue.

V Free Cash Flow (% of Annual Revenues) Chart

V Free Cash Flow (% of Annual Revenues) data by YCharts

Both companies pay a dividend, but most cash flow goes to repurchase shares, further boosting earnings growth. Fewer shares mean more profit per share. Over the past decade, Visa's share count has declined by over 18% and Mastercard's by over 20%. There is no reason it can't continue.

These market-beaters also trade at reasonable valuations today. Both companies have roughly the same price/earnings-to-growth (PEG) ratio, around 2. That's not cheap; I typically look to buy at PEG ratios of 1.5 or less. However, it's arguably fair for companies with the profit and the long track record of growth that Visa and Mastercard possess. These stocks have been "expensive" for over a decade and have crushed the market anyway.

Investors can consider adding both names to a long-term portfolio and buying on the dips to hold shares indefinitely.