Carter Bays and Craig Thomas did some very smart planning when they started filming How I Me Your Mother back in 2006. Because the whole show is framed by the voiceover of Ted telling his kids how he met their mother, they filmed footage for the scene all the way back during season one, just to keep for the inevitable ending of the show.

CT: We have not changed the very end of series at all. In fact, we shot part of it back in 2006, before Ted’s kids got much older! We just looked at that footage, which will factor into the end of the series—it totally worked and was kind of haunting to watch! Shot 8 years ago and it will now help end our series on March 31st, 2014!

CB: We’ve been slowly crafting the last 10 minutes of the show probably since it started, but the actual writing of it hasn’t happened until just recently.

Source: Collider