I'm going to expand on what I typed up earlier (since I did it on my lunch and was in a hurry). There's two types of time travel in Ocarina of Time. The first is what the Master Sword does, it's similar to Back to the Future. You travel between two points, but if you make any changes in the past, a new timeline is created. The other is basically Zelda creating a timeline with the Ocarina, which she does at the end of the game. Here's a more detailed breakdown of the 3 timelines.
Timeline 1 (the original timeline): Link pulls the Master Sword and goes into his 7 year hibernation in the Sacred Realm, this pulls him out of Hyrule for 7 years. During that 7 year span, Ganondorf begins his assault on Hyrule. Because there is nobody to wield the Master Sword, 7 Wise Men (or Sages in the GBA version I believe) seal Ganondorf in the Sacred Realm. This sets up the events of A Link to the Past, and the rest of the 2d games.
Timeline 2: (the Adult timeline): Link wakes up from his 7 year hibernation inside the Sacred Realm (just a hunch, but I think Link and Rauru are in the pyramid from A Link to the Past), Rauru sends Link back to Hyrule. At this point, we're still on timeline 1, which is why Link can go back and forth by placing and removing the Master Sword. Timeline 2 is created when Link plays the Song of Storms in the windmill in Kakariko. He alters the future by doing something in the past (like when old Biff gives young Biff the sports almanac in Back to the Future 2). When Link returns to the future by removing the Master Sword, he is traveling between timeline 1 and timeline 2 (like when Marty goes back to 1985 after young Biff got the almanac and everything was changed). Link defeats Ganondorf, the sages seal him in the Sacred Realm and the events of Wind Waker happen.
Timeline 3 (the Zelda created timeline): Zelda uses the Ocarina to send Link back to regain his childhood, however, instead of going to timeline 1, he goes to a new timeline. Because he was sent back via the Ocarina and not the Master Sword (he puts it back after he arrives) is what causes the split (this also closes off any chance of Link returning to timeline 1). In this timeline, Link warns everyone in Hyrule Castle about Ganondorf (the Triforce of Courage is his evidence) and Ganondorf's attack on Hyrule fails, he's arrested and that's when the events of Twilight Princess take place, after Link goes on his trip through Termina (and really fucks up their timeline, creating a shitload of new timelines that are doomed to end in 3 days every time).
Some people have been wondering how Four Swords can connect to Twilight Princess. Ganondorf is killed at the end of Twilight Princess when Zant snaps his neck and the Triforce of Power leaves him (the ToP was keeping him alive). A new Gerudo male is born and he either is named Ganondorf or changes his name to Ganondorf. He breaks Gerudo law and breaks into the pyramid and steals the Trident, the evil power of the Trident turns him in Ganon. Its pretty much confirmed that the Ganondorf\Ganon in Four Swords Adventures isn't the same Ganondorf from Ocarina.