Forty is a ceiling, not a sentence
This one costs women weeks of prayer every year and it is a straightforward misunderstanding.
Forty days is the outer limit of nifas. It is not a duration you serve.
If the bleeding stops at eighteen days, you perform ghusl and you resume praying at eighteen days. You do not wait out the remaining twenty two. There is nothing pious about waiting and there is nothing owed by starting.
The report about forty days describes the maximum the women of that time refrained for. Read it as a ceiling, because that is what it is.