Well consider how it starts. It starts because bad germs release chemicals that irritate the gut and interfere with water absorption, creating liquid stools. So when there’s no more bacteria creating the irritation (either because it’s flushed or the body has dealt with it), the diarrhoea stops and water is properly absorbed again.
The irritation does seem to be an immune response, but science is still trying to pin the details on that down conclusively. [source](https://www.sciencedaily.com/releases/2017/06/170614121040.htm)
Latest Answers