Inflation is red-hot right now, increasing at the highest rates in decades. Unfortunately, consumers feel the squeeze every time they go to the store or fill up their car with gas; it can feel like death by a thousand paper cuts.

Investing is something that everyone should do in any economic scenario, but owning assets is a great way to combat inflation. Likewise, some companies work in a way that makes them virtually immune to inflation or even allows them to benefit from rising inflation.

There are two fantastic companies I specifically have in mind that fit this description. But first, we need a little primer on payment networks.

Person swiping a payment card.

Image source: Getty Images.

What are payment networks?

You might not know it, but there's a lot happening behind the scenes every time you swipe your debit or credit card at a payment terminal. Data flies back and forth as soon as you make that swipe; the merchant's bank (called the acquiring bank) sends a request for payment to your bank (called the issuing bank). The issuing bank will approve or decline the payment request depending on whether it thinks you have the funds to cover the transaction.

But just like electricity needs power lines to transfer from point A to point B, payment data needs a way to go back and forth between banks. This is where payment networks come in, sometimes called "payment rails," enabling data to travel back and forth for every transaction.

There are multiple payment networks, but the two most prominent outside of China are Visa (V 0.10%) and Mastercard (MA -0.07%). Together, their networks power more than 75% of all payments made in the U.S.

Do they really dodge inflation?

OK, so they don't technically "dodge" inflation, but how these companies generate revenue is well suited for an inflationary environment. Visa and Mastercard take a small percentage of every transaction that travels on their network, similar to how you pay a toll to use the highway. 

Because their fee is percentage-based and not a fixed amount, their revenue rises with the value of transactions on their networks. Imagine spending $100 at the grocery store every week, paying with your Visa-branded bank card; if your grocery bill rises to $120, Visa gets the same percentage of a larger amount and generates that much more revenue.

In other words, inflation will lift their revenue as long as inflation doesn't curb consumer spending. If people aren't buying things, Visa and Mastercard aren't generating revenue, which isn't good for their business.

Is one better than the other?

Whether Visa or Mastercard is a better stock to own is a tough call. Below, you can see how each company's revenue growth has been nearly identical to the other for several years now. Visa does seem to be slightly better at generating free cash flow, converting 60% of its revenue into cash versus 45% for Mastercard. But considering that most companies would love to generate so much free cash flow, you will probably do well owning either company or both!

V Revenue (Quarterly YoY Growth) Chart

V revenue (quarterly year-over-year growth). Data by YCharts.

From a valuation standpoint, Visa is currently slightly cheaper than Mastercard, with the two trading at forward price-to-earnings ratios of 30 and 33, respectively. Because Visa generates free cash flow slightly more efficiently, one could argue that its lower valuation makes it the better buy today.

Both companies have grown into massive businesses, each with a market cap above $300 billion. If you've ever gone somewhere and been annoyed that payments are cash only, you've likely experienced the network effects that make Visa and Mastercard powerful.

These payment networks are crucial to the economy, and while there are other players, Visa and Mastercard dominate alongside each other. That makes either one an excellent choice for your portfolio in this high-inflation environment.