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 deploying 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 (FUND:LMVTX), has beaten the market for 15 consecutive years -- something that is 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 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 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. The central lesson: All buying and selling decisions should be guided by comparing a company's stock price with 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 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 Internet search titan Google (NASDAQ:GOOG) and its outrageous return since its initial public offering in 2004. Instead, Philip has relied on stalwarts such as Lloyds TSB (NYSE:LYG), a leading British bank with a better than 6% dividend yield. Philip recommended Lloyds when it traded for $31.79, but he figured it was worth more. Sure, Lloyds hasn't rocketed skyward like Google has, but it has beaten the market by approximately 16 percentage points since being picked. Plus, Lloyds' investors can sleep soundly at night, knowing that at current valuations, they get paid back nearly as much in dividends per dollar invested as Google takes in as revenues per dollar invested.

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, you have access to it. If not, you can 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. For example, in August 2004, I told Inside Value subscribers on a members-only message board that homebuilder Lennar (NYSE:LEN) (NYSE:LENb) looked undervalued. Its class A shares traded at the time at $42.77. That same stock recently traded hands at $42.75 and has handed its owners about $1.19 in dividends in the interim.

That may not seem like a tremendous return, but it does show the protective power you get when you buy a stock that is objectively cheap. After all, right now, we're in the midst of a panic sale of homebuilder stocks during a cooling housing market. Lennar itself even warned just yesterday that it'd miss its earnings for the quarter. Even so, investors who bought when the stock looked cheap in 2004 have still made money! It's a great illustration of how you can put into practice Warren Buffett's famous Rule No. 1: "Never Lose Money."

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. For instance, back in March of this year, I calculated that telecom equipment provider Lucent Technologies (NYSE:LU) appeared to be overpriced. Consolidation among its wireless customers diminished the need for so much overlapping equipment. At the same time, its wireline services seemed to be shifting to digital solutions that rivals provided.

In all, there looked to be little chance for further recovery. Without continued improvement, I no longer wanted to hold my shares. Using what is known as a covered call strategy, I offered to let someone else buy my shares for a total of $3.10 each. Thanks to the surprise announcement that Alcatel (NYSE:ALA) would be buying out Lucent, Lucent's shares briefly jumped high enough to make it worth it for that someone to take me up on my offer. As a result, I cashed in $3.10 each for shares that recently traded hands at $2.25, some 27% lower.

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 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 class B shares of Lennar, as well as a small number of shares of Lucent that remain in his account after his options were called away. If you email Chuck today, be sure to wish him a happy birthday. The Fool has adisclosure policy.