It seems like every second company on Wall Street is announcing a share buyback. And we're not talking pocket change here. In the last reported quarter, Applied Materials (NASDAQ:AMAT) spent $500 million, Merrill Lynch (NYSE:MER) spent a billion, Bank of America (NYSE:BAC) spent $1.8 billion, and Citigroup (NYSE:C) spent $2 billion. These are some huge numbers, and shareholders are generally delighted to hear of such buybacks. But there are actually times when buybacks are terrible for shareholders.

How do buybacks work?
A buyback simply involves a company purchasing and retiring some of its shares. This can be a great thing for shareholders, since after the buyback they will own a larger proportion of the company and its earnings.

For instance, suppose that a company has 10 million shares outstanding, and it's earning $10 million a year. That means that the company's earnings per share (EPS) would be $1. If the company then buys back 10% of its shares, that $10 million of earnings is divided up among only 9 million shares, boosting EPS to $1.11. If the shares trade at the same price-to-earnings (P/E) ratio, then the stock will rise by 11% without the company growing earnings at all.

Good buybacks
If this seems like a good deal for shareholders, that's because it is. There are many things to like about such buybacks, even beyond the increase in per-share earnings. First, it's a great way for management to use excess cash, since it will often directly benefit shareholders. In fact, Philip Durell, the lead advisor for Motley Fool Inside Value, considers share buybacks a proxy for dividends, since both dividends and share buybacks return capital to shareholders. One of the reasons Philip recommended Home Depot (NYSE:HD) a few months ago was that it had spent $6.7 billion over three years repurchasing its undervalued stock.

That raises another point. Share buybacks can serve as an indication that managers believe their company's stock is undervalued. After all, in theory, management is doing the buyback because it believes repurchasing shares offers the greatest potential return for shareholders -- a better return than it could get from expanding operations into new markets, investing in the brand, or any of the other uses that the company has for cash.

So, really, repurchasing shares can be quite a bold statement about the value of a stock. That's why shareholders have reacted so positively to MicroStrategy's (NASDAQ:MSTR) recent repurchase of 13% of its outstanding shares. If a tech company, with its potential ability to generate high-margin returns should it use excess cash to expand its operations, instead opts to buy back stock, then management must believe strongly that the shares are undervalued.

The third great thing about share repurchases is that they're relatively low risk compared to other uses for cash. Creating new products or entering new markets is risky -- if the company fails to execute, the investment could be worthless. Alternatively, using cash for acquisitions may grow sales and reduce competition, but merging businesses is tricky. Acquisitions frequently do not live up to the hype, and even successful acquisitions increase the size and complexity of the company, making management more difficult. Share repurchases, in contrast, allow a company to acquire part of itself, without all the baggage associated with buying another company.

Bad buybacks
At this point, it may sound as if managers would have to be insane, psychotic, or just a bunch of jerks to not buy back shares. Well, that's not quite the case, because buybacks can be dreadful for shareholders. The main problem is an issue that we at Inside Value obsess about: valuation.

Suppose that you, as an investor, decide to buy shares of an overvalued stock. In that case, unless a bigger idiot comes along, you're very likely to lose money on those shares. After all, if you buy something worth $10 for $20, you'll probably have a hard time finding someone willing to pay more than $10 for it, let alone more than $20. (If you're looking for a way to calculate how much a stock is worth, Inside Value has an easy-to-use intrinsic value calculator. Subscribers can use it by clicking here. Others can try it for a month with a free Inside Value trial subscription.)

When a company repurchases its own shares, the company is just like any other investor who buys the stock. If the company is buying shares when they're overvalued, then it's actually making a bad investment. In that case, shareholders would be better off if management used excess cash to pay a dividend.

One particularly bad thing that management can do is to repurchase shares to artificially support the stock price. In such a case, management uses the company's money to reward sellers of the stock at the expense of long-term holders. The sellers do well, as they end up selling their shares at a higher price than they would otherwise receive. But the long-term investors do poorly, since the company is squandering money on something that's overvalued.

Another downside is that it diminishes a company's cash balance, reducing its flexibility should a need for cash arise in the future. That's why, when evaluating whether a share repurchase is a good idea, it's important to understand whether or not the company is truly using excess cash, money that the business doesn't require.

A good example of a bad buyback was IBM's (NYSE:IBM) share repurchases in the late 1990s. IBM, like most tech stocks of the time, was overvalued. Five years later, it still hasn't returned to the level at which it traded at back then. Yet IBM was buying back shares. Even worse, if you look at the balance sheets for those years, you'll see that IBM's long-term debt increased. So, effectively, IBM was borrowing billions of dollars to repurchase its own overvalued shares. As a shareholder, this really isn't something you want your management team to be doing.

Conclusion
Thus, when a share repurchase is announced, it's important not to simply have the same knee-jerk positive reaction that the crowd has. Instead, step back and decide whether the buyback is a good idea. In the right circumstances -- when a company has excess capital and undervalued shares -- share repurchases are great for shareholders. But if the company is repurchasing overvalued shares, the buyback can actually be a sign of poor management.

If you want to step away from the crowd and buy undervalued stocks that will outperform over the long term, you should join us at Inside Value. We offer a 30-day free trial. Click here to learn more.

Richard Gibbons, a member of the Inside Value team, does not own shares of any companies mentioned in this article. The Motley Fool has a disclosure policy.