Costco (COST 1.01%) stock has been a huge winner over the past half-decade, logging a 240% gain since early 2019 compared to the 81% increase in the S&P 500. It isn't as if the company was a secret on Wall Street five years ago, either. Costco was already well-established as one of the biggest retailers on the planet in 2019. Yet shares have rallied sharply since then as the company gained market share despite the wild swings in consumer spending patterns during the pandemic and its aftermath.

There's no surefire way to know whether those market-beating gains will continue for Costco shareholders over the next several years, but a few key trends imply that this positive momentum has staying power.

Let's take a closer look.

The latest momentum

You might think Costco's presence in the mature consumer staples retailing niche would significantly limit its growth potential, but that hasn't been the case for this highly successful business. Annual revenue climbed to almost $250 billion this past year compared to $150 billion in 2019.

This increase in sales reflects market-share gains during the initial phases of the pandemic when shoppers were stocking up on essentials, which continued through the high-growth period that involved splurging on goods. Costco is faring well in the current spending environment because consumers are focusing more on prices due to high inflation.

That wide-ranging success reflects a strength that most other retailers can't match. It's also come from a mix of rising customer traffic at existing locations, a growing base of stores, and growing e-commerce sales. Each of these sales avenues can help boost revenue in the next several years as well.

Customer loyalty

Growth allows Costco to become even more efficient, which is a key pillar of its price-leadership selling approach. But the other big metric to watch is customer loyalty. Costco is a membership business first and foremost, and so its subscription trends are doubly important. They reflect brand loyalty, but also provide the income that allows the chain to keep its prices unbeatably low.

The news is unambiguously positive on this score. An incredible 93% of members renewed their subscriptions in the most recent quarter, which is a record for the business. These annual commitments are even more impressive considering how easy Costco makes it to cancel your membership and how competitive the retailing space is today. Elevated renewal rates will also make it easier for the chain to raise its fees over the next several years, likely boosting shareholder returns in the process.

Worth the price

As you might expect, investors are being asked to pay a premium for all these positive factors. Costco stock is valued at 1.3 times sales, or about double the price of Walmart shares. Its price-to-earnings ratio of 48 is also well ahead of Walmart's (28) and Target's (19).

Costco has a good chance of earning that premium in the coming years, just as it has through the last several economic cycles. Higher customer traffic at stores and online, steadily rising membership levels, and improving annual earnings will help fuel that performance.

The stock isn't perfect. Risk-averse investors might prefer a lower-priced retail stock like Walmart, for example. Costco doesn't commit to a predictably rising dividend, either, choosing instead to announce sporadic lump-sum payouts. Still, if you're looking for a world-class retailer that can generate positive returns through many selling environments, you'll likely be happy to have Costco stock in your portfolio over the next five years.