Investing in stocks can be risky -- especially if you don't know what you're doing or why you're doing it.

Shares of stock are valued based on the value of the companies that issued them. If you buy stock in the Whoa Nellie Brake Co. (ticker: HALTT) and it declares bankruptcy, you're probably going to lose money. Most well-known, growing companies don't suddenly go out of business, though. Think of Coca-Cola, IBM, Boeing, Wal-Mart, and the like. Can you imagine them not being around tomorrow?

Look at a graph of the stock market average over many years, and you'll see that it's a zig-zaggy line. The zigging and zagging is volatility. But step back, and you'll see that the jagged line slopes upward over the long haul. Despite the risk involved, the market gradually gains in value.

You can probably afford to take on some risk by investing in stocks, as long as the money invested won't be withdrawn within the next five or more years -- ideally, and to be more conservative, 10 years or longer. If you'll need the money you're investing for college or a house down payment in two years, stocks aren't a good idea -- the market could drop in the short term. But if you're investing for the long haul, you can patiently ride out downturns. Short-term investors should stick to safer plays, such as money market funds.

Even if you're nearing retirement, odds are that you won't be tapping most of your nest egg for at least five years. Therefore, much of it -- the long-term portion -- can still remain in stocks. And don't assume that just because you're in or near retirement, you need to completely withdraw from the stock market. We've got a book that addresses retirement investing -- The Motley Fool's Money After 40.

Investing in stocks is certainly not risk-free, but it can be riskier to just conservatively park all your money in an ultra-safe spot such as a money market fund or your safe in the basement. Socked away like that, it can actually lose value over time, thanks to our old friend inflation. The more you learn, the more you can manage risk. For example, know that you needn't spend time focusing on individual stocks if you're not so inclined. The best investment for most folks is an index fund.

Both Coca-Cola and Wal-Mart are Motley Fool Inside Value recommendations.

If you've got short-term money to invest, learn how to make the most of it by checking out our Savings Center. For investing in stocks and mutual funds, learn all about brokerages and find one that's right for you when you visit our Broker Center.