Varies wildly. Sometimes it's soon (though not right away - the food has to work its way through), sometimes it's hours. Depends on the dog and the type of food. Your dog should be defecating twice a day so if it goes a long time without doing anything, there could be a problem. But if you are training a puppy, then you are going out constantly because you want to reward the dog the second he/she does what it's supposed to do. Punishing it for going in the house accomplishes nothing. You have to be ahead of the dog's schedule.
You have to spend time learning your dog's habits and metabolism. A well-trained dog will have a specific location for defecating/urinating, and a schedule - ours doesn't have to go out the second she wakes up, but the last dog did. This one needs to go out 2 times a day, sometimes 3, but the other was 3-4 without fail. If you have a fenced yard and a doggie door, the dog can be trained to take care of itself. I have a small dog and live in an area with coyotes and some large dogs who roam (totally against the law of course) so mine cannot be outside alone, not ever. So she's dependent on me.
If you have a dog, work with your vet. If you don't but are considering getting one, work with a shelter to find a dog suited to your personality, lifestyle, family make-up (some are not good with kids, others are great but need a ton of exercise, and so on), work schedules, and time spent outdoors vs. in a crate. There are many breeds and many terrific mixes but you have to be honest about yourself and your needs/commitments.