We all invest for the same reason: to make money. And in order to make money investing, we need to know two key things: when to buy and when to sell.

If you can buy something for $1 and turn around and sell it for $2, then you've made money. If, on the other hand, you buy for a buck and can't find someone willing to take it off your hands for more than $0.50, you've lost money. Clearly, to make money at investing, the goal is to buy low and sell high. More than half a century ago, Benjamin Graham, the pioneer of value investing, came up with a simple way to do just that -- a concept known as the "margin of safety." By deploying this technique, investors greatly increase the chance that they won't lose their hats and the likelihood that they'll trounce other investors.

Following in Graham's footsteps, Bill Miller, who runs Legg Mason Value Trust (LMVTX), has beaten the market for 15 consecutive years -- practically unheard-of in the mutual fund industry. And Miller's long-run performance pales in comparison to that of Warren Buffett, a former pupil of Graham's and current head of Berkshire Hathaway. What's more, Graham's margin of safety is something we put to good use here at the Motley Fool Inside Value newsletter service.

Know a company's true worth
The key to success is a clear understanding of a company's true worth. With that knowledge in hand, buying low and selling high becomes a simple matter of waiting, buying a stock only when it falls below the company's true worth by a tempting margin. Once you own it, you need to keep tracking the company's value. When the stock rises to an uncomfortably high premium to its true worth, sell it. The central lesson: All buying and selling decisions should be guided by comparing a company's stock price to its true worth, not by some vague notion of what the hot stock of the moment is.

My friend and colleague Philip Durell follows that philosophy as chief analyst at Inside Value. His selections as a whole are handily beating the market's return since the newsletter's inception in 2004. His record is added proof that using a margin of safety truly does work.

Philip has beaten the market without help from the likes of natural resource firms such as GlamisGold (NYSE:GLG) or Newmont Mining (NYSE:NEM). Their run-ups over the past year, while spectacular, have more to do with changes in the market price of gold than with any particular improvements in their operations.

Instead, Philip has relied on companies with competitive moats, such as industrial titan 3M (NYSE:MMM). Thanks to 3M's large size, strong innovation, and broad product name recognition, it's one of a very small number of manufacturers that can profitably supply products through cost-cutting behemoths like Wal-Mart (NYSE:WMT). As a result of being able to supply large quantities at low prices, 3M discourages others from undertaking the costs involved in trying to compete. This helps it continually renew its moat.

Philip first recommended 3M in July 2005, after a disappointing earnings report and the loss of its popular CEO James McNerney knocked its shares for a loop. He picked it again in February, after the company committed the unforgivable (to Wall Street, anyway) sin of slightly lowering its earnings guidance. Of course, the passage of time has once again revealed 3M's tremendous strengths, and both recommendations have easily outpaced the S&P 500 in the intervening time.

Buying low with the margin of safety
Every company has what Graham calls an "intrinsic value," a measure of what a company is really worth. Finding that value is part art and part analysis. One of the most powerful tools in a value investor's toolkit is a discounted cash flow calculator, into which you put your estimate of how much cash the company will generate in the ensuing years. The calculator then tells you how much the company is worth today. Inside Value has just such a calculator available to subscribers. If you're already a subscriber, click here to access it. If not, click here to take a free 30-day trial to the newsletter and play with the calculator to your heart's content.

Once you've figured out what the company is worth, you can use that information to determine whether it has enough of Graham's margin of safety to be worth buying. Imagine buying Kinder Morgan (NYSE:KMI) in December 1999. This pipeline giant could have been picked up for about 10 times its cash flow. A discounted cash flow calculator would have called it a screaming buy. At the time, most of Wall Street's attention was focused on soaring technology companies like Sun Microsystems (NASDAQ:SUNW).

That tech bubble produced significant bargains like Kinder Morgan, among all sorts of companies that weren't deemed to be "with it." Of course, since Dec. 31, 1999, you would have more than quadrupled your money with an investment in Kinder Morgan, whereas you would have lost more than 85% of it in Sun. It's a tremendously powerful example of what your money can do if you find and buy firms trading at bargain-basement prices.

Selling high with the margin of safety
Logically, if a company trading below its intrinsic value is worth buying, then a company trading at or above its intrinsic value might be a candidate for selling. That's true even if it's otherwise a great company. For instance, back in August 2005, I mentioned that I'd love to own insurance giant Allstate (NYSE:ALL) but had shied away because I couldn't see the value at that price. In spite of the S&P 500's rise since then, Allstate's stock is down about 10% in those 10 months. While an overly destructive hurricane season was largely to blame for the stock's drop, the margin of safety had evaporated simply by virtue of it trading at that higher price. With it, so did the protection the margin of safety provided investors. With Allstate priced to perfection, it simply no longer made sense to own its stock.

Following the formula
Once you've figured out what a company is really worth, its margin of safety will tell you when it's time to buy and when it's time to sell. The lower a company's price with respect to that intrinsic value, the stronger the margin of safety, and the better the chance that buying that company will lead to a profitable investment. The higher a company's price with respect to that intrinsic value, the more that margin of safety has been reversed, and the better the chance that it's time to sell your position and take the extra profits from your bargain-hunting trip.

Like the idea of finally knowing how to buy low and sell high? Want more value investing tips and techniques? Click here for a free 30-day trial to Inside Value, The Motley Fool's home of the margin of safety.

This article was originally published on July 13, 2005. It has been updated.

At the time of publication, Fool contributor and Inside Value team memberChuck Salettaowned shares of Kinder Morgan Management, a related company to Kinder Morgan. Wal-Mart and 3M are Inside Value selections. The Fool has adisclosure policy.