Founded in 1993 by brothers Tom and David Gardner, The Motley Fool helps millions of people attain financial freedom through our website, podcasts, books, newspaper column, radio show, and premium investing services.

You might be surprised how one edges out the other.

When it comes to retail, everyone is focused on what Amazon.com is doing and which industry will get disrupted next. That makes it easy to forget the fact that e-commerce still accounts for less than 10% of all retail purchases in the United States.

What accounts for the other 90%? Tons of retailers. But two of the biggest have the stocks that will be going head-to-head in today's competition: Costco(NASDAQ:COST) and Walmart(NYSE:WMT). Over the last five years, the membership-based model of Costco has helped the company's stock double the returns of Walmart.

Image source: Getty Images.

Will Costco's outperformance continue? It's impossible to tell with certainty. But by examining the companies through three distinct lenses, we can get a better idea of which is the better buy at today's prices.

Sustainable competitive advantage

In the investing world, there's nothing more important to evaluate than the sustainable competitive advantages of companies that you want to own. These advantages are often referred to as a company's "moat."

In the simplest sense, a moat is the special something that keeps customers coming back for more -- year after year -- while holding the competition at bay for decades.

Both Walmart and Costco benefit from a crucial advantage of economies of scale: By having such a huge number of shoppers globally, with locations spread across North America and the globe, each company can bargain for lower prices from third-party vendors that it can then pass along to consumers.

But because both companies benefit from this, it's not much of a differentiator.

Costco also benefits from moderately high switching costs. Put simply, it's tough to find a better deal on food and "stuff" than what you can find at Costco. Membership fees -- which run $60 per year for a basic card -- made up 106% of the company's profit. In other words, the core business -- minus the membership fees -- ran at a loss last year, and it always has.

That's a tough business model to beat. Under normal circumstances, I would argue that this gives Costco the edge. But recently, Walmart has been able to leverage its physical locations in North America impressively in upping its e-commerce game. Sales from the channel -- catalyzed by the acquisition of Jet.com -- have given Walmart another avenue for growth. While it seems like that growth may be stalling right now, the sheer number of the company's physical locations give it an advantage in terms of expanding e-commerce presence and ease of delivery.

Winner = Tie.

Financial fortitude

Next, we have financial fortitude. While most investors in behemoths like Walmart and Costco would like to see excess cash returned to them via share buybacks or dividend payments, there's something to be said for keeping a boring pile of cash on hand.

That's because every company, at one point or another, is going to face difficult economic times. Those that have cash on hand can actually get stronger because of it -- by buying back shares on the cheap, acquiring disruptive upstarts, or bleeding the competition dry by undercutting prices to gain long-term market share.

Keeping in mind that Walmart is valued at almost four times Costco, here's how the two stack up.

Relative to their sizes, both companies have comparable free cash flows. But when it comes to the balance sheet, Costco is in a position to benefit more in the case of an economic downturn than Walmart. As such, Costco gets the nod here.

Winner = Costco.

Valuation

Finally, we have valuation. Unfortunately, there's no one metric that will tell us if a company's stock is cheap or expensive. Instead, I find it best to consult a number of data points in building out a holistic picture.

Both companies have relatively small dividends that are very sustainable and have lots of room for growth. But in terms of earning and free cash flow ratios, Walmart is clearly the cheaper of the two choices.

Winner = Walmart.

My winner is...

So based on these three criteria, we have a tie. Usually, when this is the case, I side with the company with the wider moat. Here again, however, we are stuck: Neither company is an upstart disrupter anymore. And given that their moats are equally wide, I believe that valuation should play an outsized role. Walmart is fairly valued in my opinion, while Costco seems a touch expensive.

My vote goes to Walmart.

John Mackey, CEO of Whole Foods Market, an Amazon subsidiary, is a member of The Motley Fool's board of directors. Brian Stoffel owns shares of, and the Motley Fool owns shares of and recommends, AMZN. The Motley Fool recommends Costco Wholesale. The Motley Fool has a disclosure policy.

Author

Brian Stoffel has been a Fool since 2008, and a financial journalist for the Motley Fool since 2010. He tends to follow the investment strategies of Fool-founder David Gardner, looking for the most innovative companies driving positive change for the future. Follow @TMFStoffel