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 a dollar 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 buy it 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 (FUND:LMVTX), has beaten the market for 14 consecutive years -- practically unheard-of in the mutual fund industry. Bill'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.

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 the company's 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 have just about tripled the market's return since the newsletter's inception last year. His record is added proof that using margin of safety truly does work.

Philip has beaten the market without help from the likes of Internet search titan Google (NASDAQ:GOOG) and its 250% return since its initial public offering last August. Instead, Philip has relied on stalwarts like Lloyds TSB (NYSE:LYG), a leading British bank with a better than 7% dividend yield. Philip recommended Lloyds when it traded for $31.79 but he figured it was worth $44. Sure, Lloyds hasn't rocketed skyward like Google has. But Lloyds' investors can sleep soundly at night, knowing that at current valuations, they get paid back more in dividends per dollar invested than Google takes in as revenues per dollar invested. Not only that, Inside Value readers got the chance to buy Lloyds at an attractive discount to its true worth.

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 or not it has enough of Graham's margin of safety to be worth buying. For example, last August I told Inside Value subscribers on a members-only message board that homebuilder Lennar (NYSE:LEN) (NYSE:LENb) looked undervalued, with its Class A shares trading for $42.77 and its Class B shares at $39.43. My discounted cash flow calculations at the time placed Lennar's value at $59.33. That put its A shares at about 28% undervalued and its B shares at almost 34% undervalued. (Another way of saying that: The A shares had a 28% margin of safety and the B shares had a 34% margin.) That discount gave investors a great margin of safety. The larger the margin, the better the buy.

Now, less than a year later, Lennar has rocketed upwards. Its A shares recently traded for $66.25 and its B shares at $61.51, giving investors in either class a better than 54% return, before dividends!

Selling high with the margin of safety
Logically, if a company trading below its intrinsic value is worth buying, then a company trading above its intrinsic value just might be a candidate for selling. Take pharmacy services management company and Inside Value selection Omnicare (NYSE:OCR). When Philip Durell uncovered it in October, it was trading at $29.51 a share, and he pegged its value at $41. Recently trading at $47.36, investors have seen a better than 63% return in under a year with this discovery. More importantly, from the perspective of margin of safety, it's now trading at almost 18% above where Philip first pegged its fair value.

Since it's above that fair value price, it has sparked a firestorm of debate on the Inside Value discussion board dedicated to Omnicare. The question is whether or not Omnicare's successful bids for rivals NeighborCare (NASDAQ:NCRX) and RxCrossroads will add enough value to justify holding at this price, or if Philip's original value calculations are still accurate. (Current members can see the debate by clicking here. Want to see, but aren't yet a member? Click here for a free trial.)

Assuming Philip's original valuation is still accurate, then Omnicare's market price has rocketed past its fair value, and the margin of safety is gone. (In fact, there's a negative margin of safety -- a margin of peril, perhaps?) Anyway, you're being offered the chance to sell Omnicare not for its intrinsic value, but at a price well above intrinsic value. So, if we're happy as value investors to buy when a stock trades well below intrinsic value, we may also be wise to sell when a stock is well above intrinsic value.

The Foolish bottom line
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 the 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 the 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 of Inside Value, The Motley Fool's home of the margin of safety.

At the time of publication, Fool contributor and Inside Value team memberChuck Saletta owned shares of Lennar and Omnicare. The Fool has adisclosure policy.