If you did not use your full annual allowance in previous tax years this can be carried over to the current tax year to allow you to contribute more than the £40,000 cap. Unused allowance from the previous three tax years can be used but you need to earn enough in the current tax year to cover your full contributions.
As an example, let’s say you have £50,000 of unused allowance from previous tax years and an income of £70,000 this year; since you can’t contribute more than 100% of your earnings in any case, your total contribution cannot be more than £70,000 which means you can only carry forward £30,000 of unused allowance from previous years (£40,000 allowance from this year + £30,000 previous unused allowance = £70,000).
See also our tax benefits of a pension blog post.