It’s important to understand how and when bubbles in the economy occur because what happens after they explode can deeply affect you and the world around you. That isn’t easy; behind all the spreadsheets, financial statements, economic models and rules and regulations are people acting emotionally, doing things that are not rational or justified by numbers.

Psychological factors were at work behind the crisis because it was emotion which helped to lead the U.S. into the current economic crisis-the mania and over-optimism behind the housing bubble, a lack of self-control by consumers hooked on debt, banks who lent money (and earned hefty fees) on the impossible dream of ever-rising property values, politicians fueled by the desire to get re-elected and a Federal Reserve that was too scared of deflation and therefore did a poor job of controlling interest rates.

At their core, bubbles occur when foolish people are willing to buy something simply because they believe there’s a bigger fool somewhere out there they can sell to for a higher price.

Real estate booms and busts happen in very long cycles so when housing prices are going up, few remember that they ever went down. This was certainly the case in the recent crisis, since housing prices only went up between 1975 and 2006. According to economist and Yale professor Robert Shiller, property markets are especially prone to booms and busts because they’re inefficient. Property markets (residential and commercial) have no central clearinghouse of information about prices, transaction costs are high, trading is infrequent, and the supply of property is relatively fixed in the short term.

Because credit is required in most cases in order to make a purchase, housing booms and busts are linked to the banking system. When the economy is doing well it tends to drive up real estate prices, and banks tend to lend to support that because people now have collateral. Optimism about rising prices feeds the frenzy and as an increasing number of novice investors enter the market, prices and enthusiasm also increase. The ensuing upward spiral can last for a very long time, and regulators tend to support it because they really like to see loans that are collateralized by a tangible asset like real estate.

Everyone involved in the bubble falls victim to “disaster myopia” (meaning they’re too near-sighted to see the longer term risks) either because they simply can’t imagine a downturn happening, or they assume the probability of it happening is so low that it really isn’t worth worrying about.

People often make poor economic choices because they are overly optimistic about what they will do in the future. For example, people transfer credit card balances over to cards with high long-term interest rates because they believe they will pay everything off before the much lower teaser rate expires. (Most don’t.) Borrowers who default on payday loans typically pay interest amounting to 90% of the loan’s principal before they finally give up and stop making payments.

One study of a health club found that members who worked out on average just four times a month chose to pay a monthly membership fee of $85, even though the gym also offered a pay-as-you-go rate of $10 per visit. When people are polled about their beliefs as to what they’re going to do, there often is a refusal to accept reality.

Carl Case and Robert Shiller (of the S&P/Case-Shiller HPI) did a survey in 2003 of homeowner attitudes in four major markets — Boston, Milwaukee, Los Angeles and San Francisco. In all four markets, more than 80% of homeowners surveyed said they believed home prices would rise over the next few years. When homeowners were asked how much they expected the price to change in the next months, responses ranged from 7.2% in Boston to 10.5% in Los Angeles.

Even more surprising was that when faced with the question, “On average over the next 10 years, how much do you expect the value of your property to change each year?” homeowners in Milwaukee said they expected prices to rise by 11.7%. Homeowners in San Francisco said they expected a 15.7% return.

In the recent bubble, both buyers and lenders were overly optimistic about what the future would bring. Buyers ignored the possibility that they might not be able to keep up on payments because they assumed the prices of homes would go up and they would be able to sell or refinance. Likewise, lenders ignored the possibility of default because rising home prices had made it easy to get bad loans off the books.

Economist John Kenneth Galbraith wrote about this in his book The Great Crash, a history of the events leading up to the Great Depression: “The bankers were also a source of encouragement to those who wished to believe in the permanence of the boom. A great many of them abandoned their historic role as the guardians of the nation’s fiscal pessimism and enjoyed a brief respite of optimism.”

So, how can you tell if a bubble is occurring? The easiest way is to use the most basic of economic laws, the law of supply and demand.

Prices rise (meaning inflation occurs) when there is too much money chasing too few items. In the case of the recent housing bubble, prices rose as demand increased, which is as expected. However, the difference here was a supply/demand imbalance with regard to the credit needed to make the purchases because as demand for credit rose, the price of the credit fell and the availability increased.

There’s also a more cynical way to look at things; when completely unsophisticated “investors” are clamoring to get into a market, in general it means that the market is at, or very close to, a top.