Retiring by age 40 is entirely possible if you have been able to save up enough of your income in a high yield savings account or have invested your money into stocks and bonds.
Another way to retire by age 40 is to have some good passive income sources such as from a blog and advertisements or by doing affiliate marketing.
Or you can also hire a property manager and own some rental properties where you make some good passive income through renting out homes or apartments and let the property manager do the work.
That will allow you to retire from your current job by age 40 because at age 40 you cannot collect social security benefits so you'll need an income source.