Beginning investors learn early on just how important it is to have a diversified portfolio. Many workers, though, neglect the value of their human capital when they're figuring out how to put their retirement-plan money to work. That's the big reason why analysts like the Fool's own John Rosevear see investing your 401(k) money in your employer's stock as potentially the biggest mistake you'll ever make.

But, while I generally agree with John's sentiment, there are some cases where buying some employer stock makes for a smart investment. I'll explain more about that later in the article, but first, let's take a look at the case against employer stock.

All your eggs in one basket
The basic idea of diversification is that you want to have a wide variety of different investments that don't move in lockstep with each other. That way, if one of your stocks takes a nosedive, the rest of your portfolio will hopefully cushion the blow.

You can apply the same principle to your overall financial picture. The biggest asset that most people have is their human capital: the skills they sell to employers in exchange for a paycheck. And although most workers have a knowledge base that they can put to use at a variety of different employers, longtime workers at a particular company inevitably learn things that are of unique value to their current employer.

Put another way, you've already made a big investment by choosing the employer you work for. If something happens to your employer's financial prospects, then you could find yourself without a job and scrambling to find somewhere else to work. If the same problem also causes your employer's stock to tank, then having a big chunk of shares stuck in your 401(k) just exacerbates an already serious problem.

Making a big mistake
Unfortunately, employees at many companies are highly concentrated in employer stock. Procter & Gamble's (NYSE: PG) defined-contribution plan has 43% of its assets in P&G shares, while Coca-Cola (NYSE: KO) employees have fully half their 401k money invested in Coke stock, according to BrightScope.

At those companies, share-price declines have generally been mild. But employees at other companies, ranging from Enron to Eastman Kodak, haven't fared nearly as well. Over the years, that has prompted lawsuits by retirement plan participants at numerous companies to try to recover losses, with one of the more recent ones coming at Bank of New York Mellon (NYSE: BK). Moreover, Bristol-Myers Squibb (NYSE: BMY) and others have responded by limiting the amount of employer stock you can buy in your 401(k).

When it's smart
But there's a corollary to the theory that you shouldn't invest in your employer's shares because you don't want a double-whammy if the company goes under. It's this: If you think a threatened layoff might actually benefit the company's stock price, then owning shares in your 401(k) or elsewhere be a smart way to hedge the downside of losing your job.

For some companies, layoffs are almost a final admission of failure, acting as the writing on the wall of an imminent death spiral for the company both as an employer and as an investment. But in many more cases, investors view layoffs as a good thing, as they indicate a willingness to cut costs in the name of boosting shareholder profits. For instance, earlier this month, shares of PPG Industries (NYSE: PPG) soared after the company said it would cut 2,000 jobs and restructure its operations.

If you think the odds are good that you might get laid off as part of what you think will be a successful restructuring, then investing in your employer's stock could help you profit from your own misfortune. The positive effect will likely be minimal compared to your personal loss of income, but every little bit helps -- as long as you're comfortable about your employer's overall business prospects.

Be smart
Of course, it's often hard to tell exactly what financial condition your employer is in. If you're not sure, then buying employer stock can be a risky bet. But for the limited purpose of hedging focused layoff risk, owning employer stock might not be as bad a move as it usually is.

In general, you can usually find better investments than your employer's stock. Check out the Motley Fool's special report on retirement to learn the names of three promising stock picks for long-term investors. It won't cost you a thing, but don't wait; get your free report today while it's still available.