Wayne Gretzky, the legendary hockey player, was never the strongest guy on the ice. What he lacked in heft, however, he made up for with a canny ability to remain alert and calm and to trust his instincts in the midst of a frequently violent frenzy. These qualities allowed Gretzky to become the greatest practitioner of the Canadian national pastime.

Similarly, people who remain alert and calm and who trust their instincts in the midst of a frequently violent frenzy excel at what has become something of America's national pastime: trying to build a fortune in an economy marked by investment bubbles. Bubbles are generally viewed as the invisible hand's way of dashing entrepreneurial gains that came too easy, but the opposite is often true. By their nature bubbles present opportunities for entrepreneurs to make big profits.

And we've certainly got our share of bubbles today. It's impossible to open the business pages without reading about bubbles (real or imagined) in real estate, Web 2.0, and clean technology. Of course, a bubble's narrative arc--a burst of frantic building and excess capacity, followed by outlandish hype and cutthroat price competition, and finally bankruptcy and consolidation--is nothing new. It happened in telegraph and railroads in the 19th century, in stocks and credit in the 1920s, and, of course, in the dot-com world in the 1990s.

Every generation or so, a hot new technology comes along or theorists develop a new set of economic assumptions that supposedly change the rules governing economic and commercial behavior. As government policy encourages investment in a particular sector, promoters concoct pro forma numbers that extrapolate impressive short-term trends indefinitely into the future. (Remember the 1999 book Dow 36,000? It was something of a remake. In the fall of 1929, Yale economist Irving Fisher proclaimed that "stock prices have reached what looks like a permanently high plateau.")

Drawn in by the promise of unfathomably vast markets, many bubble participants get hurt--especially large corporations, which have a knack for making giant bets at precisely the wrong time. In America, a good business idea gets funded--and funded again. Entrepreneurs stake out ground, and deep-pocketed investors and corporations follow. The result: Capacity always expands faster than demand. Three telegraphs connected New York City and Boston in the 1840s. A half-dozen transcontinental railroads were built in the years after the Civil War. Enough fiber-optic cable was laid by behemoths like WorldCom and Global Crossing (NASDAQ:GLBC) in the 1990s to last two generations. In each instance, unfortunately, there simply wasn't enough traffic to go around.

Looking at bubbles through history, it becomes apparent that the best long-term business opportunities don't arise during a bubble but after the bubble bursts. Timing a crash is a difficult, perhaps impossible, proposition. Having studied the dynamics of bubbles and what usually follows, I believe entrepreneurs can draw some important lessons about when and how to expand businesses in booming fields that appear to be headed for a bust. They are:

1. Bubbles are bipolar. The frenzy and irrational optimism that break out during an upswing swiftly morph into paralysis and irrational pessimism come the bust. Corporations, embarrassed by the huge investments they made--often right at the top--are eager to write down their devalued assets and move on. When they do, the building blocks of good businesses are suddenly available on the cheap. Consider the case of Charles Merrill. He fled the retail brokerage business in the early 1930s. But in 1940, when Wall Street was still trying to shake off the Great Depression, Merrill was able to merge his company with E.A. Pierce Co., the nation's largest brokerage firm at the time, for less than $2 million. By 1944, Merrill Lynch (NYSE:MER) had dozens of offices across the country serving 250,000 customer accounts. And in the postwar years, as more investors cautiously dipped their toes back into the markets, guess who was there to welcome them?

More recently, after the dot-com bust, the price of everything associated with Web technology and the Internet plunged, from servers to Bay Area real estate. In 2000, the median annual lease price for a 155 MBPS unit of fiber-optic capacity from Los Angeles to New York was $1.8 million; by 2005, it had fallen to $76,800. San Francisco office space went from $77 per square foot in 2000 to $29 in 2004. It then follows that at the beginning of the decade, Philip Rosedale's vision of creating an online world that could be inhabited by thousands of players simultaneously would have seemed prohibitively expensive. But after the bubble popped, the prices of that world's main costs--a massive server grid, office space in San Francisco, and data transmission, Web hosting, and programming capacity--had fallen so sharply that it made sense. Thus the success of Second Life (see Inc.'s February cover story), which has emerged as one of the most popular and intriguing online destinations.

2. Customers brought in during the boom are yours for the taking after the bust. Just because bubble-era companies disappear, it doesn't mean bubble-era consumers have left the building. During bubbles, a great deal of money and energy are spent building up what I call the mental infrastructure surrounding a new technology--convincing people to send grain by rail instead of by canal boat, to buy stocks instead of hiding cash under the mattress, to make phone calls over the Internet instead of over phone lines, to buy hybrid vehicles instead of inefficient SUVs.

And so even when the infrastructure businesses associated with a particular bubble collapse--I'm talking about all of those busted telegraph, railroad, and telecom companies--entrepreneurs can step in and tap into the legions of users who were coaxed into the market by them. Back in the 1840s, for example, the telegraph encouraged people to regard information as something they could trade, buy, and sell. Although virtually all of the companies that strung up telegraph wire wound up filing for bankruptcy, companies like Dun & Bradstreet (NYSE:DNB) found enduring success. D&B, which traces its origins to 1841, expanded to meet the needs of new users by gathering and disseminating credit-rating information. The road to success, it turned out, was through content and not infrastructure, although one wouldn't have existed without the other.

Another survivor who served new users was Thomas Edison. In 1869, Edison, a former telegraph operator, went to work on Wall Street at a company that supplied the prices of gold via telegraph to investors. Edison lived in a way that would be familiar to modern-day programmers, subsisting on the 19th-century equivalent of Red Bull and Twinkies--coffee and apple pie. Then one day he came up with the idea for a stock ticker that could deliver financial data more cheaply and efficiently than the telegraph. The invention was a hit, and Edison was able to sell the rights to it for $40,000. He used that money to set up his own shop, from which he invented the electric light bulb and various recording devices.

Fast-forward to today. Many nascent alternative energy infrastructure businesses are surely destined to fail. Companies that manufacture solar installations will likely have a tough time. Overcapacity inevitably leads to intense competition and falling prices--a natural process that can be deadly for those with high fixed costs. As companies bludgeon one another into oblivion, however, they attract new users, a process that snowballs as prices drop. And the real winners are likely to be service companies that develop expertise in customer service. A company that maintains and upgrades residential solar installations, for example, likely will find itself flooded with orders even as manufacturers of solar panels struggle. Again, entrepreneurs should think about services that don't require huge capital investments--say, providing kits that allow existing automobiles to run on ethanol or software that enables a home to switch between generating electricity from a small wind turbine and a solar panel.

3. Bubble survivors can get real big real fast. During infrastructure bubbles, bandwidth hogs are easily frustrated. What's a bandwidth hog? A company whose business model rests on distributing and transmitting a high volume of products and services over a new commercial infrastructure. In a bubble, bandwidth hogs struggle because costs are high and the emerging systems frequently don't function as advertised.

When a bubble bursts, however, bandwidth hogs are among the biggest beneficiaries of excess capacity. After the Civil War, for example, as railroads slugged it out, the cost of freight fell sharply. The average rate per ton mile of freight fell from $1.93 in 1867 to 84 cents in 1895. This made it possible for entrepreneurs to acquire agricultural commodities in bulk, process them efficiently in a central location, and then ship the finished goods to distant points of sale. Taking advantage of the new cost structure in 1882, Gustavus Swift began building a national meat-packing and distribution company with his famous refrigerated rail cars. He was followed quickly by Armour & Co. and Hormel (NYSE:HRL). Suddenly, a host of branded, processed food products burst onto what had suddenly become a national market: Campbell's (NYSE:CPB) soup, Pillsbury flour, Heinz (NYSE:HNZ) ketchup, Coca-Cola (NYSE:KO), and more.

Similarly, in this decade, a host of businesses that rely on universal, cheap broadband have minted money for their founders. YouTube went from zero to 100 million videos per day in literally the time it takes an infant to learn to walk. Skype, the Internet phone company, was launched in August 2003, dark days indeed for the Internet economy. It roped in millions of users by relying almost solely on viral marketing and was purchased by eBay (NASDAQ:EBAY) for $2.6 billion--half in cash--in 2005.

The biggest entrepreneurial success story of this past decade--and perhaps of all time--neatly encapsulates all three of these lessons. Google (NASDAQ:GOOG), which was founded in 1998, became the world's largest search engine just as the bubble was about to burst in 2000. Google was able to build a business on the cheap, hiring engineers and computer scientists, many of whom were seeking new employment after the bust. A bandwidth hog, it lashed together hundreds of thousands of inexpensive servers and capitalized on the steadily rising adoption of broadband.

The company's success is due in no small part to its superior search algorithms. But all that code would have been worthless if not for the hordes of new users who continued to throng the medium. Google thrived by tapping into the rapidly expanding installed base of U.S. Web surfers, which now stands at 172 million, by selling ads to hundreds of thousands of online advertisers desperate for leads, links, and clicks, and by placing ads on blogs and social networking sites. As of early April, it sported a market capitalization of $146 billion.

Stock analysts routinely point out that past performance should not be regarded as a guarantee, or even an indicator, of future performance. True enough. But when it comes to business, history does have a way of repeating itself.

Daniel Gross, a columnist for Slate and The New York Times, is the author of Pop! Why Bubbles Are Great for the Economy (Collins), from which this article is adapted.