We all invest for the same reason -- to make money. And 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, 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), beat the market for 15 consecutive years -- a record 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. What's more, Graham's margin of safety is something we put to good use at our 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 -- 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.

That often means not giving into the temptation to buy "the next big thing." As sexy as the marketing pitch may be, the next big thing often falls flat on its face. After all, look how far satellite radio pioneers XM Satellite Radio (NASDAQ:XMSR) and Sirius Satellite Radio (NASDAQ:SIRI) have fallen since the turn of the millennium. As these two flailing former bitter enemies have shown, all the latest technology in the world is meaningless if a company cannot profitably capitalize on it.

The strategy simply works
Instead, value investing relies on companies with proven strong businesses and competitive moats, such as used car superstore CarMax (NYSE:KMX). While smaller in overall sales than archrivals AutoNation (NYSE:AN) and Penske Automotive Group (NYSE:PAG), CarMax has an edge by being focused almost entirely on used cars. That focus has allowed it to be an innovative leader in providing customer-focused service and to become a trusted name in what's often considered to be a shady business.

That customer focus and strong reputation have certainly paid off. Since being picked for Inside Value in December 2005, CarMax has easily outpaced the S&P 500. That's in spite of the persistent fear that certain car manufacturers' financial troubles and an uncertain economy would continue to pressure the used car market.

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 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 such a calculator available to subscribers -- if you're already a subscriber, you can access it here. If not, you can get access by taking a free 30-day trial of the newsletter.)

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. Imagine buying the forerunner to oil giant ExxonMobil (NYSE:XOM) at the start of 1995. At a split-adjusted $15 per stub, you would have been buying shares in a business priced as though the multidecade history of low oil prices would be a permanent fixture in the world economy. Yet throughout its history, oil has been a cyclical commodity, prone to occasional price spikes. Not quite 13 years later, on the back of oil's recent climb, the company traded hands at $92, up a staggering 500% from that start date.

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. Inside Value advisor Philip Durell recommended just such a sell for toy giant Mattel (NYSE:MAT), well before its recent spate of recalls of lead tainted toys. It wasn't a psychic premonition of things to come that led to that sale. Instead, it was simply a realization that the company's stock had catapulted from the bargain basement and could no longer be considered value-priced.

While Mattel's recall may have been a surprise, the fact is that bad news happens to every company from time to time. In fact, nasty headlines like that are what often lead to the discounts that allow value investors to swoop in and buy at low prices in the first place.

Follow 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 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 knowing how to buy low and sell high? Want more value investing tips and techniques? Start with a free 30-day trial of Inside Value, The Motley Fool's home of the margin of safety.

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

At the time of publication, Fool contributor and Inside Value team member Chuck Saletta owned shares of Mattel. CarMax is an Inside Value selection. The Fool has a disclosure policy.