You can always contribute to an IRA. Just can't always deduct the contribution for a traditional IRA. And, can't always contribute to a Roth IRA.
Traditional IRA stops being deductible when your modified AGI (eg Your W-2 taxable earnings with some adjustments) exceeds 85k for married filing jointly.
for a Roth IRA, modified AGI cap married filing jointly is 160k.
So, if you grossed 165, and put more than 5k into a 401(k) you will have reduced your income level below the Roth Cap.
For IRA purposes, earnings do not include any deferred compensation.
http://www.irs.gov/pub/irs-pdf/p590.pdf