Overall, 2013 was a great year for tech investors: The Nasdaq soared, rising nearly 40%, outpacing both the S&P 500 and the Dow Jones Industrial Average. But some tech stocks did better than others. Notably, Microsoft (MSFT -2.45%), Pandora (P) and Hewlett-Packard (HPQ 0.11%) all enjoyed terrific years, rallying about 40%, 200%, and 100%, respectively, in 2013.

These gains are all particularly notable in light of the fact that all three companies had somewhat difficult years. Whether it be a declining business, uncertain future or competitive threats, Microsoft, Pandora, and HP were all challenged in 2013.

Microsoft's Windows 8 gets off to a rough start
Microsoft shareholders had to be pleased with 2013. Although Microsoft wasn't the best performing tech stock of the year, a 40% rally for such an enormous company with a solid dividend is quite impressive.

That gain, however, comes in spite of what was, at best, a mixed year for Microsoft. Windows 8, Microsoft's most radical reimagining of its Windows operating system in nearly 20 years, largely fell flat, attracting widespread criticism and seeing sluggish adoption rates. Microsoft's Office 365, its cloud-based version of its dominant Office software, has proved to be quite popular, but 2013 was a year of emerging competition -- Google with Apps, and Apple with free iWork, came after Microsoft Office like never before.

This was the first full year Microsoft had its own PC hardware on sale, and there, too, it struggled. In July, Microsoft took a $900 million writedown on its Surface after sales came in far short of expectations.

Perhaps a bright spot given the amount of investor criticism his tenure has attracted, Microsoft CEO Steve Ballmer announced in August that he will retire. However, Ballmer's replacement has not yet been chosen, leaving Microsoft's future direction somewhat uncertain.

Apple, Google, Spotify come after Pandora
Pandora's rally was far more impressive than Microsoft's, but as a smaller, more speculative stock, a 200% rally is not particularly unusual. Rather, what is unusual is that the gain came in a year when Pandora saw more competition than ever before.

In September, Apple improved its iTunes app with the addition of iTunes Radio. Now, nearly all Apple devices have a built-in Pandora competitor, one with nearly identical functionality. Pandora's management claimed the company was resilient in the face of competition from Apple, but the total number of active listeners dipped in October, the first full month of iTunes Radio's availability.

Google released Google Music All Access in May, and then ported the app to iOS in November. Google's app isn't fully a Pandora competitor, in the sense that it's built around on-demand music more so than on-radio functionality, but it is a competing music app all the same.

Google Music is more like Spotify rather than Pandora, but there, too, Pandora has been challenged. Earlier this month, Spotify began offering a free option on mobile devices, a product that could ultimately weigh on Pandora's business.

Hewlett-Packard's business continues to decline
HP's gain was better than Microsoft's but fell far short of Pandora's. Still, anyone who bought shares of the PC giant at the beginning of last January has nearly doubled the investment today.

HP shares have soared even as the company's business has continued to shrink. In November, HP reported fiscal-year revenue that was down 7% from the prior year. Although HP has branched out into server technology, PCs continue to make up nearly one-third of the company's total revenue, and 2013 was a poor year for traditional PCs. PC shipments saw notable declines in 2013, with the first quarter recording the worst drop ever. 

HP did return to profitability in 2013, exceeding expectations, but overall, 2013 was a year of contraction -- not growth -- for HP.

Will these stocks snap back in 2014?
With all three stocks posting such notable rallies in 2013, investors might expect all three to snap back next year. While anything is possible, investors should look for improvement in each firm's underlying business prospects to justify, let alone boost, their present valuations.