Praise be to Allaah.
Forty days is the longest period that the woman in nifaas can refrain from praying and fasting, so long as blood is still flowing. After that, she should do ghusl and pray, and consider herself to be in a state of istihaadah (irregular vaginal bleeding which is neither menstruation nor nifaas) if the bleeding does not stop. Umm Salamah (may Allaah be pleased with her) said: “At the time of the Messenger of Allaah SAWS (peace and blessings of Allaah be upon him), the woman in nifaas would sit (i.e., refrain from praying and fasting) for forty days…” (Narrated by al-Tirmidhi). For more details on this topic see Question #319.
With regard to the belief that a woman has to stay in her house for forty days after giving birth and not go out, this is a mistaken belief and women do not have to do this. It is permissible for them to go out during these forty days to any place she wants, so long as she fulfils the shar’i conditions (i.e., hijaab etc.)