We usually tell everyone (including our kids) pretty much right away. I just can't keep my own secrets, so we spill it pretty early!
If I had a history of early pregnancy loss or some such thing, I would wait until I was into the "safety zone". I don't feel that it's necessary to involve kids in a miscarriage, as they likely won't grasp it all and it may be too much for them.
As for the questions..... ugh! You know they're coming. So come up with some age appropriate explanations to have at the ready. My oldest is 10, and they took sex ed this year. Needless to say, he knows how it all came about, lol. (I think he was a little grossed out) My 7 1/2 year old didn't seem to care. He remembered when his sister was born, that was enough of a frame of reference for him. And my 4 year old has the typical questions. How did the baby get in you? How will she get out? Does the baby hurt you? And so on. I try to be honest (no "storks" here), but not un-necessarily explicit. She just needs general answers for the most part. We can fill in the details later, lol!