We all invest for the same reason: to make money. And to make money in 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 something 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 employing this technique, investors greatly decrease the chance that they'll lose their hats and increase 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 -- something that's practically unheard of in the mutual fund industry. And Miller's long-run performance pales in comparison with that of Warren Buffett, a former pupil of Graham's. What's more, Graham's margin of safety is something we put to good use here at the Motley Fool Inside Value investing 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 to buy 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.

Using this method, I managed to earn more than 31% in just over a year on an investment in real estate firm AmREIT (AMEX:AMY). That easily lapped the S&P 500 index's total return of around 7.1%. When I bought the company, it was trading below its book value and hiking its dividend payments every month. In essence, I was getting paid ever-increasing amounts of money to buy a firm that the market was judging as worth more dead than alive.

When I sold, the dividends had stopped rising and the shares had leaped well beyond their book value. With my two buy criteria gone, there was no reason to hold. About 18 months after my sale, the stock recently traded about 9% below my sell price. 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.

The method works
My friend and colleague Philip Durell follows that philosophy as chief analyst at Inside Value. His selections as a whole are beating the market's return since the service'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 energy giants like Sunoco (NYSE:SUN). Sunoco had a fabulous run-up thanks to Middle East tension, the infrastructure damage caused by Hurricanes Katrina and Rita, and booming Chinese and Indian economies. Yet as its recent weakness reminds us, oil remains a cyclical commodity, and the oil companies are only as rich as the stuff they pull out of the ground.

Instead, Philip looks for companies with competitive moats, such as financial software firm Intuit (NASDAQ:INTU). Once customers set up with Intuit's Quicken, TurboTax, and QuickBooks programs, they don't tend to undertake the expense and time to switch to rivals' offerings. Thanks to those significant switching costs, Intuit has been one of the few firms capable of holding its own against larger and better-capitalized software companies like behemoth Microsoft (NASDAQ:MSFT).

Philip recommended Intuit in February 2005, after the company's stock had taken a nosedive during one of the market's periodic panic fits. And sure enough, since his recommendation, Intuit has outperformed the market, returning around 82.1% during a period in which the S&P 500 provided 15.7%.

Buying low with the margin of safety
Every company has what Graham calls an "intrinsic value," a measure of what that company is really worth. Finding that value is part art and part analysis. One of the most powerful tools in a value investor's tool kit 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, you have access to it. If not, you can get it by taking a free 30-day trial to the newsletter. Then you can 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. In December 2004, for example, using just such a cash flow calculation told me that employment and income verifier TALX (NASDAQ:TALX) was significantly undervalued. Less than two years later, the market has caught on, launching TALX about 115% above my purchase price.

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 just might be a candidate for selling. Take the case of a former Inside Value watch-list firm, health-care services company Cardinal Health (NYSE:CAH). After the stock relentlessly rose from his discovery price, Philip removed it from consideration. In essence, the gap between price and value had vanished, and its margin of safety had evaporated. Since getting the boot in July 2005, the stock's performance has largely tracked the S&P 500.

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? Start up a free, 30-day trial to Inside Value, The Motley Fool's home to 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 Microsoft and TALX. Intuit and Microsoft are Inside Value selections. The Fool has adisclosure policy.