|The first game allowing playable Koopas|
So here's the deal. Super Mario Bros. is clearly set during a war, presumably between the Mushroom Kingdom and whatever Kingdom Bowser is in charge of (remember, his name at the time was King Koopa). We'll call it the Koopa Kingdom. Mario might be a Mushroom soldier, but his uniform certainly isn't regulation. Most likely he's a commando on a one-man crusade to rescue the princess and topple Bowser's reign. That said, it could also be interpreted that Mario is a revolutionary, trying to end a cruel monarchy, and that the entire game is set in only one kingdom - that is, Bowser is the King of the same country where Toadstool is Princess. It remains unclear, but I prefer the latter theory, if only because there is no apparent delineation between levels supposedly set in different kingdoms.
A particular narrative delight is 6-3, which gives us a glimpse at the pre-war Mushroom Kingdom. You may remember 6-3 as the black-and-white level, at the opening of which Mario softly utters "I remember now...". The black-and-white imagery is a common visual trope, indicating that this scene takes place years in the past. 6-3 is idiosyncratic in that it is the only one of the 32 stages that is completely devoid of the standard Koopa armies. No Koopers, Goombas, or even Fishy-Bloos, just a few solitary Bullet Bills foreshadowing the onslaught to come. Some have suggested that this is the first day of the Koopa invasion, a D-Day of sorts, which Mario is now recalling, remembering how far he's come.
The game is spread over the course of eight "worlds", each culminating in a castle infiltration. It seems clear from this that Mario is embarking on eight different military campaigns, each targeted at one of Bowser's strongholds. The post-boss dialogue - "our princess is in another castle" - makes explicit that Mario takes down each of these fortresses with the expectation that the princess is held within. Considering the span of his conquest and the effort it would realistically take for one man to overcome an army, it seems natural that each of these "worlds" may take place over a span of time closer to a year than the few minutes it takes to play through in the game.
This is where things get controversial. As I see it, it seems a surety based on Mario's extensive spy/informant network that he does indeed have the correct castle each time, but King Koopa manages to evacuate the princess just in time to move to his next stronghold and leave Mario fighting a Replicant and rescuing a Toad. This explains how Toadstool was able to give birth to eight Koopa children in the span of the first game (the third being an immediate sequel). She was trapped in each castle for a year and had no choice but to... well, you've been to the Internet, I don't need to explain it to you. As Koopa has never had another romantic interest (nor do there appear to be adult females of his species), this is the only provable origin on the Koopa Kids. Also, The Adventures of Super Mario Bros. 3 pretty heavy-handedly hints that's what happened. Plus Peach is openly Bowser Jr.'s mother, so it's not like the two are... strangers to intimacy.