Image via WikipediaP/E is basically price per share of the stock divided by annual earnings per share.
Beware that there are several definitions of P/E, depending on which earnings you use. The commonly used definition is trailing P/E, which is earnings in the last 12 months. A "forward" P/E on the other hand, uses "projected earnings" over next 12 months. There's also another variation that uses last six months and projected six months.
P/E Ratio is a comparative stat. By itself, it means nothing. It is only useful when compared to some OTHER P/E ratio.
In a way, it's like a vehicle's MPG rating. If I tell you that this vehicle's MPG is 6.5 on the highway. You'd call that a gas guzzler.
But what if I tell you that this vehicle is a 45' motorcoach (i.e. a highway bus), and the industry average for a bus is merely 5.5 MPG? (and that's DIESEL, by the way). So now this is actually quite economical.
To compare MPG, you need to know the TYPE of vehicle. Sports car? SUV? Sedan? Truck? etc. Then you compare it against type average, or against another specific model.
P/E ratio is the same. It is usually used to measure whether the stock is overvalued, or properly valued, but it is impossible to use by itself. You need to compare it to something, either another company's P/E, or the sector average P/E.
A related number is P/E10, which uses averaged earnings of past 10 years. This should even out the spikes in earnings, if any. However, it won't help much if company is young.
Another related number is PEG, which is P/E, divided by earning growth rate. Say the company has grown its earnings by 8% every year. And their PE right now is 32 to 1. If you divided 32 by 8, you get 4, which is the PEG. This number is popularized by Peter Lynch, the Wall Street legend and former manager of the Magellan fund. He stated that people will gravitate toward companies with high growth, causing their stocks to be overvalued. Thus, if you divided the P/E by growth, you'll normalize the number, making for a more meaningful comparison against other companies. According to Lynch, most companies should have a PEG of 1, at least for Stalwarts (see 6 Stock archetypes). If a company has a PEG of 2 or high, it is probably overvalued, and vice versa.
There is myth called "rule of 20". Basically, it says that 20 is the threshold between value and over-valued, if "adjusted for inflation", by adding the annual rate of inflation to the entire stock market's P/E ratio. If that's over 20, the market is overvalued, and you may want to get out.
Frankly, with so many stocks now, there is really no such thing as "the entire stock market". You usually will have to calculate the P/E for a specific index, such as the DJIA, or the S&P 500, and so on. The problem is the market can and have gone higher. In 1995, the market is at P/E of 22. In 1999, peak of dot.com boom, market's P/E is at 33! However, In 2003 the S&P 500's P/E is creeping back to 30. Now the S^P 500's P/E is back down to 20 or 21.
However, keep in mind that different industries have different average P/E ratios. The Internet/tech sectors tend to have much higher P/E ratios, average of 51, according to USA Today's column. Again, proving that it really is all relative. A P/E of 40 would be high compared to overall, but low against tech sector.
[For more on the "Rule of 20" and dozens of other Wall Street myths and see them dissected, get the book "Buy the Rumor, Sell the Fact" from McGraw Hill. It's published in 2004, so some of the stats are a bit out of date, but it's still a fun read. ]
However, looking just at P/E is NEVER enough. There are companies with no P/E (they likely haven't had any earnings, or are currently losing money, or simply don't report any earnings), for instance. You need to take into account their debt situation (just because they're earning money doesn't mean it's NET profit), their cashflow, and so on. Thus, it's best to keep your eyes open and use multiple ratios compared with multiple other companies to determine what to buy.