There is nothing better than a company with plenty of cash on its balance sheet. A large cash pile removes uncertainty about the company's financial future, but it can also change valuations.

For example, a company that is sitting on a large amount of cash will usually trade at a premium to its peers, as its cash pile is priced into the company's valuation. Effectively, a company with a large pile of cash is less risky than one without, so the premium applied is due to the lower amount of risk taken on.

However, some analysts consider a large cash pile to be a sign that management is not spending enough to stay ahead of the game or returning enough cash to investors. While this can be true, with the market recently hitting all-time highs and opportunities for growth few and far between, I would rather companies hoard their cash. It is either hoard or buy back stock at all-time highs and acquire peers that could be overpriced.

What's more, with such uncertain economic times upon us, it is prudent to pay a bit extra for the security of a solid cash position on a company's balance sheet. So which companies are sitting on the most cash, and will their hoards last?

Here are three cash kings worthy of a closer look:

Company

Cash Net of Debt (millions)

Shares in Issue (millions)

Share Price

Cash per Share

P/E

P/E Ex-Cash

Bed Bath and Beyond (BBBY)

$838

227

$77.30

$17.70

16.9

13

Red Hat (RHT)

$863

196

$43

$7.35

55.9

46.3

MasterCard (MA -0.07%)

$6,000

120.4

$684.18

$49.80

33

31

Source: MarketWatch. Figures in millions current as of the end of the third fiscal quarter.

The housing recovery
Bed Bath & Beyond sits on a cash pile of $838 million, and given the company's net income margin of 9%, this cash pile looks set to grow further.

Indeed, Bed Bath & Beyond's cash flows are strong, as the company does not need to spend a huge amount on capital projects and can just sit back and let the cash flow in. Obviously, the company has to spend some cash wrestling with peers for customers within the highly competitive home retail market. However, it would appear that Bed Bath & Beyond has nailed its marketing strategy, as the company's operating margin is near 15%, which stands out among home retail/variety stores, which usually have margins in the single digits.

 The company is also riding the domestic economic recovery and the resurgence in housing and home improvement spending.

Stripping the cash out of Bed Bath & Beyond's valuation gives a P/E of only 13 -- low, considering that the company is expected to grow earnings per share by around 10% this year and then a further 12% during 2015.

Subscription cash flows
Red Hat is a software company that derives a significant proportion of its sales from subscriptions. Subscriptions to software packages are usually recurring and high-margin: After the initial software-development costs are out of the way, the company is able to sell its product at very low cost to itself.

All in all, this makes Red Hat extremely cash-generative -- something some companies can only dream of. Indeed, during the company's fiscal fourth quarter, the company generated $303 million in subscription revenue and $137 million in operating cash flow.

By themselves, these numbers are irrelevant. However, if we dig through Red Hat's financial statements, we can see that the company has spent $562 million buying back its own stock with cash from operations during the last four quarters alone. The company's net cash balance hardly changed during the period. With around $500 million in cash on its balance sheet, Red Hat could easily afford to undertake buybacks much bigger than $562 million if it drew on its cash reserves.

Still, over the four quarters, these buybacks have only reduced the number of shares outstanding by 2.2% -- hardly life-changing.

Plastic revolution
Much like Red Hat's, MasterCard's business model and cash generation rely upon repeat transactions, which generate income for the company for a low cost. While the company does have to fight off competition almost constantly, now that MasterCard is well-established in the market with a global payment network behind it, the company is a veritable money-printing machine. Within its third-quarter results, the company reported that its cash balance had expanded from $5.1 billion at the end of the fiscal second quarter to $6 billion, or $49.8 per share.

These quarterly results reveal how cash-generative MasterCard actually is. What's more, this huge balance of cash, along with the company's cash generation, is enabling MasterCard to swallow up its own shares. MasterCard's shares are expensive at more than $700 a pop, so the company has to spend a serious amount of cash to reduce the number of shares by a significant amount. Indeed, during the fiscal third quarter, MasterCard spent nearly $1.7 billion in cash to buy back 1 million shares -- only 0.8% of its shares outstanding.

That said, this buyback was funded in its entirety by free cash flow, and the company could have actually spent a lot more, as MasterCard generated more than $3 billion of free cash flow during the quarter. These buybacks are driving up earnings per share, which are widely expected to hit $26.30 for fiscal 2013 and then jump to $31 for fiscal 2014. All in all, with a solid cash balance behind the company, MasterCard's investors are likely to be well-rewarded over the next few years.