Apple (AAPL -0.81%) is still basking in the limelight since reaching a market cap of $1 trillion back in August. The company's high-end products and services have delighted its customers for decades, and the recent refresh of its iPhone lineup indicates that there's no slowing down any time soon.

Meanwhile, IBM (IBM -0.35%) has been working on transitioning away from its legacy hardware products over the past few years, and it's in the middle of reinventing itself for a tech world that's increasingly focused on services revenue. The company's stock has fallen out of favor for some, but its commitment to its dividend has helped keep it on income investors' radar.

So which company looks like the better buy right now? Let's examine a few key aspects of both companies to get a better idea.

Image of computer screen with charts on it.

Image source: Getty Images.

Financial fortitude

Investors should have some reassurance that their investments will be safe if the stock market takes a negative turn. To help determine this, it's worth looking at how strong a company's finances are based on its cash, debt, and free cash flow.

Here's how IBM and Apple compare on these points:

Company

Cash

Debt

Free Cash Flow (TTM)

IBM

$14.3 billion

$45.5 billion

$12.1 billion

Apple

$243.7 billion

$114 billion

$58.5 billion

Data sources: Yahoo Finance and Morningstar. Cash includes long and short-term investments.

It's worth pointing out here that about $31 billion of IBM's debt is from the company's global financing business, which is backed by IBM's $28 billion in financing receivables. If you subtract out those receivables from the company's balance sheet, there's actually about $17.5 billion in corporate debt on IBM's books. But even though IBM has substantially less debt than Apple, the company's cash and investments are still far lower than Apple's, which means the iPhone maker would be able to handle a downturn much better.

Winner: Apple.

Valuation

There are many metrics to use when valuing a company, but let's take a look at both companies' current price-to-earnings ratios (P/E), their forward P/Es (which are based on future earnings projections), and their enterprise value-to-EBITDA ratios to get an idea of each company's value.

Company

P/E Ratio (TTM)

Forward P/E

EV / EBITDA

IBM

24.5

10.8

10.1

Apple

20.4

16.5

14.1

Data source: Yahoo Finance.

No one metric is perfect for determining whether a stock is a good value or not, but they're all helpful when comparing two companies head-to-head. Apple's P/E ratio is a bit lower than IBM's right now, making it appear more inexpensive, but both are well below the current tech sector average P/E of about 33. Meanwhile, IBM may look a bit cheaper than Apple based on its forward P/E and EV / EBITDA ratios. Because there's no clear winner here, I'm marking this one a tie.

Winner: Tie.

Competitive advantage

Investors need to be on the lookout for companies that have sustainable competitive advantages, meaning that they possess something that their competitors would have a tough time replicating.

For IBM, there doesn't appear to be much of an advantage right now. The company certainly has proven that its hardware and services can be valuable to other businesses, but the very reason why it's currently evolving into more of a services company -- with less focus on hardware -- is because it was essentially forced into that model.

Other tech companies have adapted much faster than IBM, including its cloud computing competitors Amazon and Microsoft, which are in a much better position than IBM in the cloud computing market.

Compare that with Apple, which has one of the most recognizable brands in the world and is continually able to get its customers to buy its new products even as it continues to raise product prices. Apple has also wisely built out a strong services business that will be hard for its competitors to replicate. The company now generates about 18% of its top line from services (including Apple Music, the App Store, and Apple Pay), and it grew revenue year over year in this segment by 31% in its most recent quarter, showing just how well the company has built a complete ecosystem of products and services.

With Apple's strong brand and its ability to sell millions of devices each year at high margins -- and then turn around and sell customers services on those devices -- it's the clear winner in this category.

Winner: Apple

The verdict

There's not much of a contest between these two tech giants. Apple is in much better shape financially, its stock is still relatively inexpensive compared to the overall tech sector, and it has a sustainable competitive advantage due to its vast ecosystem of devices and services.