In recent years, Macy's (M -2.49%) stock has taken shareholders on a roller-coaster ride. After bottoming out below $5 in April 2020, Macy's shares surged during 2021 as sales and earnings recovered rapidly. But after peaking around $40 in November 2021, the stock has sagged again, falling below $15 last week.

Recession fears likely explain the stock's dreadful performance over the past year and a half. Indeed, Macy's stock trades for less than four times earnings today. However, even if a recession begins later this year, Macy's is well positioned to weather it. That makes Macy's shares a great buy for investors who are willing to be patient for a few years.

A potential retail outperformer

Buying a consumer discretionary stock -- let alone a department store -- might seem like a strange move when inflation remains high and a recession may be looming. However, Macy's is much better off than many other discretionary retailers, especially its rivals in the department store space.

First, Macy's operates across multiple brands and store formats that appeal to shoppers across the income spectrum. Its upscale Bloomingdale's brand posted stronger sales results than many other discretionary retailers last year, as rising inflation didn't impact its affluent customers much. The company's Bluemercury beauty brand performed even better, achieving record-breaking sales in fiscal 2022.

And while the core Macy's banner is facing some sales pressure due to the impact of inflation and slowing economic growth, Macy's continues to expand its Backstage off-price concept. That gives customers an option to trade down to lower-priced merchandise within the same store. As a result, the company has been reporting better apparel-sales trends than the likes of Target since 2022, in a big shift from prior years.

Second, Macy's has dramatically improved its inventory management in recent years. The company entered fiscal 2023 with $4.27 billion of inventory, which was down 2.6% year over year and down 17.8% from where inventory stood at the beginning of fiscal 2020. That will minimize its need to offer margin-crushing discounts in the face of softer sales trends.

M Inventories (Annual) Chart

Macy's Inventories (Annual), data by YCharts.

Macy's still projects that comparable sales will fall 2% to 4% this year and that adjusted earnings per share (EPS) will decline to between $3.67 and $4.11, compared to $4.48 last year and $5.31 in fiscal 2021. But that would compare very favorably to the company's fiscal 2019 adjusted EPS of $2.91 -- a remarkable achievement in light of this year's tougher macroeconomic environment.

The balance sheet is solid

In a cyclical industry like discretionary retail, many companies see sales and earnings fall when the economy weakens. That alone can't explain the massive plunge in Macy's stock price.

Investors would have good reason for caution if Macy's had a weak balance sheet. However, since 2016, the company has reduced debt from a peak of over $7 billion to just $3 billion. Furthermore, less than $100 million of this debt matures before 2028. Thus, a short-term decline in Macy's earnings shouldn't have long-term repercussions.

M Financial Debt (Quarterly) Chart

Macy's Financial Debt (Quarterly), data by YCharts.

Indeed, with Macy's likely to generate roughly $1 billion of free cash flow this year and no pressing need to pay down debt, management could elect to capitalize on Macy's depressed share price by buying back stock. The company entered the year with $1.4 billion remaining on a $2 billion share-repurchase program authorized in 2022.

Huge upside potential

Many investors are understandably wary of investing in department stores. Indeed, the golden age of the department store is long over. But Macy's has proven quite resilient over the past few years.

With debt now firmly under control, Macy's should be able to return the bulk of its free cash flow to shareholders going forward. Steady share buybacks could drive Macy's stock significantly higher over time, just as shares of regional department store chain Dillard's have nearly quadrupled over the past five years.

DDS Chart

Dillard's stock price, data by YCharts.

Best of all, Macy's real estate portfolio provides investors a crucial margin of safety. In total, Macy's real estate is likely worth at least $10 billion, far above the company's current enterprise value of approximately $6 billion. Between this downside protection and its rock-bottom valuation, Macy's stock offers a compelling balance of risk and reward for patient investors.