Real were given an early warning as Legia's Vadis Odjidja-Ofoe hit the woodwork with the game still goalless.
Bale opened the scoring on 16 minutes after the Welshman was picked out by Danilo, and the hosts were 2-0 up soon after thanks to a Marcelo effort that took a wicket deflection of Tomasz Jodlowiec, who was unlucky to have the strike chalked up as an own goal.
However, Legia responded almost immediately as Danilo conceded a penalty and Miroslav Radovic stepped up to score from the spot.
The Polish outfit nearly drew level with 10 minutes of the first half remaining but Michal Kucharczyk sent a golden opportunity wide and Real made the visitors pay as Marco Asensio grabbed a third for the La Liga giants moments later after thanks to a Cristiano Ronaldo assist.
Substitutes Lucas and Alvaro Morata completed the rout in the second half as Legia began to tire.
Lucas scored within five minutes of his introduction after being picked out by Morata, who then added Los Blancos' fifth with Ronaldo providing the assist on 84 minutes.
Real remain second in the Group F standings, level on points with leaders Borussia Dortmund, and Legia are bottom of the standings having lost all three of their Champions League games to date.