American Express (AXP -0.62%) and Visa (V -0.23%) are both legendary stocks.

Visa shares have skyrocketed 20 times in value since the company's initial public offering (IPO) in 2008. American Express shares, meanwhile, have increased in value by nearly 6,000% since 1977, the year of its IPO.

Both companies operate high-quality businesses with proven long-term track records. But which stock is a better buy right now?

Invest in this type of business

One of the most powerful advantages a company can have is the magic of network effects. What exactly is a network effect? In a nutshell, it's a characteristic that allows a company to grow stronger the larger it gets.

Visa and American Express are perfect examples. If only a few people used Visa or American Express credit cards, most merchants wouldn't accept them. Why build out a particular payment system for only a few customers? Conversely, if only a few merchants accepted Visa or American Express, most people wouldn't be interested in using that form of payment, for it wouldn't work at most locations.

It can be difficult to avoid this chicken-or-the-egg problem. But when a company cracks the code, the magic of network effects is unleashed.

As more people become Visa or American Express users, more merchants begin accepting that form of payment. A greater number of merchants accepting Visa or American Express attracts more users, which in turn attracts yet more merchants. It is a positive feedback loop that can persist for decades.

In many ways, American Express and Visa are still riding the wave of network effects. There's a reason just four companies dominate nearly 100% of the U.S. credit card market. Visa commands the largest market share at 49.5%, with American Express coming in last at around 7.4% . (Mastercard and Discover are in second and third place, respectively.)

It will be incredibly difficult for other players to enter this consolidated market due to the difficulty of achieving long-term network effects. Companies like Visa and American Express, meanwhile, can continue to benefit from their incumbent market power and brand recognition.

Put simply, network effects are a growth driver that can propel a stock for decades. Both Visa and American Express have cracked the code.

Which stock is better -- Visa or American Express?

If network effects were responsible for the long-term growth of both companies, then it follows that the company with stronger network effects will produce superior results in the years to come. With more than 7 times the number of cards in circulation, Visa has a strong lead in this department.

Visa's superior network effects are partially evident in the company's return on equity -- a measure of how much net income flows to shareholders. After years of improvement, Visa's return on equity is around 46%, roughly 1.5 times higher than American Express.

Even more impressive, Visa was able to post these superior return figures while employing less debt than American Express. Often, companies are able to boost returns on equity by leveraging the balance sheet and taking on debt. By improving its return profile without a sizable increase in debt, Visa has proven that it can scale its business more efficiently than the competition.

V Return on Equity Chart

V Return on Equity data by YCharts

On paper, Visa appears to be the better business. It has a higher return on equity, lower debt levels, greater market share, and arguably superior network effects. But there is another aspect to consider: each stock's valuation. It is possible, after all, to overpay for a great business. Even if American Express is less efficient as a business, a cheap stock price could make it the more attractive option.

Which stock is cheaper today? Without a doubt, the answer is American Express.

Right now, American Express stock trades at a free cash flow yield of 10.5%. That means a $100 investment would lay claim to around $10.50 in free cash flow. Visa, for comparison, trades at a free cash flow yield of just 3.3%. That's only $3.30 in free cash flow per $100 invested.

On an earnings basis, the situation remains unchanged. American Express trades at an earnings yield of 5.1%, whereas Visa stock trades at a yield of only 3.1%.

V Free Cash Flow Yield Chart

V Free Cash Flow Yield data by YCharts

Both Visa and American Express make sense as long-term investments. Visa can likely better defend its market share and grow more efficiently than American Express. However, American Express stock is clearly the better bargain.

Which stock should you buy? The answer, surprisingly, is both. By diversifying your investment, you don't have to pick one winner over the other. Both operate high-quality businesses with strong economic moats. Visa has the advantage of size, while American Express has the advantage of being a better value.

So when faced with the dilemma of choosing between two quality businesses, the answer is often to buy both.