Tech stocks have generally done well this year, staging a solid recovery from a tough 2022. But not all tech stocks are created equal. AT&T (T -0.76%) looks like a bargain, while Apple (AAPL -0.21%) looks severely overpriced.

Buy AT&T

There are two core reasons to invest in AT&T stock: The valuation and the dividend. The stock price reflects an extreme amount of pessimism that looks overdone, and the dividend, while unlikely to grow quickly, has a sky-high yield.

AT&T expects to generate at least $16 billion of free cash flow this year despite a slower pace of wireless subscriber additions. With a market capitalization of $114 billion, the stock trades for roughly 7 times free cash flow. That looks like a bargain.

On top of a rock-bottom valuation, AT&T's dividend now yields 7%. That dividend probably won't grow much in the coming years – the company's failed media acquisitions have left it with a debt-heavy balance sheet. But the dividend looks sustainable. If AT&T hits its guidance, the dividend will consume about 50% of free cash flow.

AT&T won't be immune from a slowdown in consumer spending if a recession strikes this year or next. If smartphone users delay upgrades to avoid shelling out for new phones, AT&T will not only see lower revenue from equipment sales, but there will also be fewer opportunities to win over customers from rivals. Global smartphone shipments tumbled 14.6% year over year in the first quarter .

While AT&T isn't an exciting stock, the company operates in a capital-intensive industry with only two major competitors and provides a service that has become essential for nearly all customers. There are risks, including the high debt load and the chance of a bigger slowdown in subscriber gains. But an extremely pessimistic valuation gives investors a sizable margin of safety.

Avoid Apple

Apple is a great company. The iPhone is iconic, and most iPhone users don't even consider an alternative when it's time to upgrade. But the stock is expensive. Apple's market capitalization crossed the $3 trillion mark on Friday. Based on the average analyst estimate for full-year earnings, Apple stock trades at a price-to-earnings ratio of about 32.

Are Apple's current earnings sustainable? It's hard to say. The company's profits shot up early in the pandemic, driven by intense consumer demand for PCs and gadgets. It's now starting to decline.

AAPL Net Income (TTM) Chart

AAPL Net Income (TTM) data by YCharts

Through the first six months of fiscal 2023, Apple's net income fell by 9.2% year over year. Revenue was also down. While the iPhone eked out a sales gain in the second quarter, sales were down through the first half of the year. The services business, one of Apple's key growth engines, is barely growing at all, and Mac sales have tumbled as demand for PCs slumps.

If you had a crystal ball and knew that Apple's earnings would steadily rise going forward, paying 32 times earnings might make sense. But there's a real chance that Apple's earnings have peaked for the time being.

Apple's search for a new product that can grow to the scale of the iPhone has so far come up empty. The company plans to launch a $3,500 mixed-reality headset in early 2024, but it's hard to see that selling millions of units in its current iteration. VR and AR headsets have been slow to gain any real traction, and Apple's entry probably won't change things.

Many investors may view Apple as a safe stock that can be counted on in an uncertain economic climate. But Apple's lofty valuation makes the stock far riskier than many assume.