One of the most amazing features of the mainline Pokemon games is the enormous backwards compatibility with previous games in the series. Sun and Moon are the 7th generation of Pokemon games and it's possible to import Pokemon from as back as Ruby and Sapphire--the 3rd generation!
While you don't need to import your old Pokemon to enjoy these games, eventually you'll probably want to do so to help complete your Pokedex or whatnot. Still, with so many games out there, it can be difficult plotting a route to your old friends, which is where we come in!
At the time of writing, Pokemon Bank is your one and only connection with the rest of the Pokemon universe. Some time during January 2017, there will be a free update to Pokemon Bank that will allow you to transfer Pokemon between Pokemon Sun and Moon and Pokemon Bank.
Pokemon Sun and Moon Special Demo
If you have the Special Demo available on the same 3DS (or 2DS) as Sun or Moon, you can send any items or the special Ash-Greninja from the demo to Sun or Moon. None of this is essential, but the Ash-Greninja cannot be obtained elsewhere and the items are a nice bonus.
Pokemon X, Y, Omega Ruby and Alpha Sapphire - 6th Generation
Pokemon acquired in any of the 6th Generation games can be sent straight to Pokemon Bank--and thus can be transferred to Sun and Moon after the January 2017 update. Easy peasy. You simply need to have Pokemon Bank available on the same 3DS (or 2DS) as your 6th generation game(s).
One Way Trip
Before you consider moving your Pokemon from one generation to the next, you need to know that Pokemon transferred to the next generation can not be sent back to the previous generation. It's essentially a one-way trip.
This holds true for Pokemon Sun and Moon and the 6th generation games. Now, you may be slightly confused. Certainly, Pokemon Sun and Moon and the 6th generation games can both directly access Pokemon Bank--no issues there.
However, any Pokemon originating from a 7th generation game or that has been transferred to one will be highlighted in Pokemon Bank and can only be transferred to a 7th generation game. If you try to transfer it to a 6th generation game, you simply won't be allowed.
Pokemon Red, Blue and Yellow (Virtual Console) - 1st generation
No, your eyes are not fooling you. You can indeed transfer Pokemon from the very first generation to Sun and Moon, but only if they come from the 3DS Virtual Console editions. Around January 2017, at the same time as the Pokemon Bank update, there will be an update to the Poke Transporter companion app.
After the update is available, you can use Poke Transporter to transfer Pokemon from the Virtual Console Pokemon Red, Blue or Yellow to Pokemon Bank. To do so, Pokemon Bank, Poke Transporter and the 1st generation Virtual Console game must all be available on the same 3DS (or 2DS).
From One to Seven
Although Poke Transfer sends the 1st generation Pokemon to Pokemon Bank, be aware that they can only be transferred to Sun and Moon, not any of the 6th generation games.
Pokemon Black, White, Black 2 and White 2 - 5th Generation
Pokemon caught in the Unova region can be transferred using Poke Transporter, just like the Pokemon from the 1st generation games. Likewise, you'll need Pokemon Bank, Poke Transporter and the 5th generation game all available on the same 3DS (or 2DS).
Pokemon Diamond, Pearl, Platinum, HeartGold and Soul Silver - 4th Generation
This is where things get a bit more complex. Now you'll need two DS or 3DS systems, one with a copy of a 4th generation game and the other with a copy of a 5th generation game. In the 5th generation game, you need to access the in-game PokeTransfer feature and transfer wirelessly.
Pokemon Ruby, Sapphire, Emerald, FireRed and LeafGreen - 3rd Generation
Finally we come to the end of the road. For this, you'll need a DS. Insert a 3rd generation game into the GameBoy Advance cartridge slot and a 4th generation game into the DS card slot. In the 4th generation game, you can use the in-game Pal Park feature to transfer between the games.