The Federal Reserve has now officially raised its benchmark overnight lending rate, the federal funds rate, by a full half-point, the largest hike in two decades, as the Fed attempts to rein in inflation. In light of the Fed having now executed rate hikes at each of its last two meetings, and expectations that there is more to come, I think it's safe to say that we are in a rising-rate environment.

Few know how to play difficult market conditions better than the legendary investor Warren Buffett and his company Berkshire Hathaway (BRK.A -0.81%) (BRK.B -1.14%), which both know how to beat the market. Here are three good Buffett stocks to invest in during a rising-rate environment.

1. Mastercard

As one of the largest payment rails in the world, Mastercard (MA -0.21%) facilitates payment transactions in more than 200 countries. In 2021, Mastercard saw roughly $7.7 trillion flow through its network and had close to 2.6 billion cards in circulation.

Because Mastercard sets the rules for its ubiquitous network and serves as a middleman in transactions that go through its network, the company collects a small percentage fee on each transaction. So, if people are paying more for goods and services due to rising rates or higher inflation, Mastercard will collect more for each transaction. Additionally, having already built and scaled its payments system, it likely won't experience the same strain on its costs or debt as other sectors do.

Now, if rising rates and other actions by the Fed tip the economy into a recession, that could bring down consumer spending, which would cut into Mastercard's business. But the consumer is still in extremely strong shape right now, recent recessions haven't lasted long, and consumers will still be spending across the network for necessary goods and services. In addition, Mastercard is benefiting as more consumers and businesses forgo cash for digital payments.

Warren Buffett.

Image source: Motley Fool.

2. Bank of America

Few banks will benefit as much from rising interest rates as Bank of America (BAC -0.39%), the second-largest bank by assets in the U.S. Bank of America is extremely asset sensitive, meaning that when the Fed hikes rates, more of the yields on assets such as loans will reprice higher than the yields on liabilities such as deposits. This will benefit net interest income (NII), the profits banks make on loans, securities, and cash after funding those assets. At the end of the first quarter, Bank of America said a 1% parallel move in short- and long-term interest rates would result in roughly $5.4 billion more of NII over the next year. Bank of America's first-quarter NII of $11.6 billion was already $1.4 billion higher than a year earlier.

Now, rising interest rates can increase bank deposit costs, and Bank of America -- like Mastercard -- would not benefit from a recession. But Fed Chairman Jerome Powell recently said an even more aggressive 0.75% rate hike is not being "actively considered" at future meetings, which is a good sign. Furthermore, banks just made it through the worst of the pandemic, so Bank of America should be able to handle a much-less-severe recession.

3. Berkshire Hathaway

The last name on the list is the conglomerate Berkshire Hathaway itself, which runs a range of businesses under the Berkshire brand in a variety of different sectors, including energy, insurance, and real estate. Berkshire also owns a range of diversified businesses that do not operate under its brand, such as the large insurance company GEICO and the Burlington Northern Santa Fe Railway. In addition, Berkshire also manages an equities portfolio that is valued at more than $350 billion and invests in all sorts of stocks, including tech companies, banks, energy, consumer food and groceries, and more.

Berkshire can do well in a rising-rate environment because it has so much exposure to financials such as banks and insurers that naturally do better by investing cash at higher interest rates. Additionally, Berkshire's equities portfolio holds more than $106 billion of cash that will also earn more in a higher-interest-rate environment.