To put it plainly, I like companies that produce strong cash flows. That's because they have a proven ability to turn earnings into cash, and they can use this cash to invest in the business via capital expenditures, which should help growth prospects.

What's left over is free cash flow. Companies that generate prodigious amounts can reward shareholders with dividends and share buybacks. These two companies have proved they can produce cash in all kinds of economic environments.

Three people sitting around a table with a laptop on the table.

Image source: Getty Images.

Costco

Costco Wholesale (COST 1.01%) has a remarkable ability to attract and retain paying members. It ended last year with more than 58 million members and had a renewal rate over 90% in the U.S. and Canada. Clearly, its customers find the membership fee worth it to shop for high-quality merchandise at attractive unit prices.

This translates into higher profits and free cash flow. In the fiscal year that ended on Aug. 30, 2020, Costco's free cash flow was $7.2 billion. This was 53.5% higher than 2018's figure. It used part of this bounty to pay $1.5 billion in dividends last year.

The cash-producing machine kept chugging along this year, too. Free cash flow for the first three quarters was $3.5 billion, more than 32% higher than a year ago.

Its cash generation has allowed Costco to increase dividends annually since its first payout in 2004. Even better, the board of directors has a history of declaring large special dividends every two to three years. The last one was in December, when it paid $10 per share.

Walmart

Operating discount stores for nearly six decades, Walmart (WMT -0.08%) attracts more than 240 million shoppers every week with its very low prices. Walmart is laser-focused on costs, passing on savings to customers, making it very hard for other retailers to undercut its prices.

With its free cash flow, it can continue investing in initiatives to remain competitive with Amazon (NASDAQ: AMZN). This includes investing in e-commerce and omnichannel initiatives, such as the membership subscription program Walmart+.

After annual capital expenditures of over $10 billion for the last several years, Walmart has plenty left over. Last year, its free cash flow was $25.8 billion. Management used part of this to reward shareholders, paying $6.2 billion in dividends and spending $2.6 billion to repurchase shares.

In the first half of this year, the company produced free cash flow of $7.4 billion. For fiscal 2022, management expects to spend $14 billion on various initiatives such as its supply chain, automation, and customer-facing technology.

Walmart's success and earnings power allow it to continue investing for the future and pay higher dividends. Earlier this year, the board of directors raised the payout, making it 48 straight years of annual increases.

The old saying cash is king is very true when looking at which companies to invest in. Both Costco and Walmart have simple businesses that revolve around keeping prices low. This attracts a lot of customers, no matter the economy, helping keep cash flow high even during difficult times.