All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
The bleeding that you saw during the period of 40 days is considered postpartum bleeding and if there was a period of purity that interrupted it (for at least one day and one night), then it is considered as a valid period of purity. Therefore, you should have refrained from prayer in the period of 40 days during the time you see bleeding, and when the bleeding stopped, you should have performed Ghusl and prayed.
As regards the bleeding that you are seeing after 40 days according to the description that you mentioned, then it is not possible that it is all menses because the length of the period of the two bleedings and the period of purity between them exceeded 15 days which is the maximum period of menses, and the period of purity between two bleedings did not reach 13 days which is the minimum period of purity between the two menses (according to the Hanbali School of jurisprudence). Therefore, it becomes clear – according to what you mentioned – that you had bleeding outside your monthly menses.
Hence, if you have a known monthly period, then you should consider the bleeding that you saw in your monthly period as menses, and whatever exceeds it [this period] is bleeding outside your monthly menses.
If you do not have a previous regular period, then if you can distinguish the characteristics of the blood of menses by its color, smell and thickness and the pain that accompanies it, you should consider this as menses and consider the other blood as bleeding outside the monthly menses, on the condition that the bleeding that you distinguish [to be as menses] is possible to be menses in the sense that the totality of its time-period is not less than one day and one night and is not more than 15 days and nights.
If you can not distinguish the bleeding of menses from other bleeding, then you should refrain from the prayer for the regular period of most women in your family, like six or seven days of the days during which you see bleeding, and consider them as menses and consider what is beyond this as bleeding outside your menses.
According to some scholars, the days that you consider as menses should start at the beginning of each (lunar) month. According to some other scholars, you should try your best to act according to what you most predominantly believe to be menses, and this is the most correct opinion.
When the days that you consider as menses expire, you should perform Ghusl and during the days when you have bleeding outside your monthly menses, you should perform ablution for every obligatory prayer after its time starts, and you should also put a napkin or the like on your private parts, and the rulings of the pure woman apply to you. For more benefit, please refer to Fataawa 145201, 129256, 128778 and 108423.
Allaah Knows best.