My understanding is that it is 35 full qualifying years. I have a lot more than that, but some were contracted out, and I am buying those years back.
You can decide whether it's worth it to you by looking on the website at your personalised forecast (and do check your NI contributions record, as a lot of them are apparently wrong).
In my case, I would have been down by about £20 a week on a full state pension, but if I continue to buy the years back at a cost of about £900 a year, by the time I get my delayed State Pension I will get that £20 a week back. It's a gamble on how long you think you will live, and who knows if the pension age will move again, but I think it is worth it for me.
I agree Synchroswimmer that it is very galling to have to do this after paying in and paying tax for over 40 years, but what can you do? I sometimes wonder whether I did the right thing by working.
Also, note that Full Qualifying Years doesn't just apply to whether you are contracted out. The years run from April to March, so if you started working, or went back after maternity leave etc in, say, September (as many people in education would do) you lose that whole year, and if you leave work in February, you lose that year too.
Be careful not to make assumptions - check your own record, rather than make calculations based on what you think you have paid.