How long should you use a mattress before replacing it?

We’ve had a mattress for probably 7 years and I think it may be time to replace it because it just doesn’t seem comfortable anymore. Any idea on how long you should keep a mattress?