You also must close all retirement accounts of the same type to calculate the loss. So, if you're trying to claim a loss on your 401(k), you must close all your 401(k)s. Then, total your nondeductible contributions and the current value of the accounts, and you can write off the difference if the current value of the accounts is lower.
But this is inconvenient for two reasons. First, if you withdraw money from your 401(k) before age 59 1/2, you will pay a 10% early withdrawal penalty. This may negate some of the benefits of writing off the loss. Second, if you take the money out of your 401(k), you're giving up the tax advantages it offers, and your money will no longer grow as quickly unless you invest it in something else.
For these reasons, it's unwise to claim a tax deduction on a 401(k) loss unless you're older than 59 1/2 and plan to use the money to cover your retirement expenses in the near future. Otherwise, try one of the suggestions above.