Barca are in Group G with Benfica, Spartak and Celtic, while Real are in Group D with City, Ajax and Borussia.
Monte Carlo: Defending champion Chelsea will take on Juventus, while Real Madrid will face Manchester City in this season's Champions League group stage.
Thursday's draw pitched the holders against a Juventus side that stormed to the Serie A title and was unbeaten in all competitions last season apart from the Italian Cup final. Group E also includes Shakhtar Donetsk and Champions League debutants Nordsjaelland.
Real have been handed the toughest draw — with three league champions in Manchester City, Borussia Dortmund and Ajax in Group D.
Bayern Munich, last year's runners-up, are in Group F with Valencia, Lille and BATE Borisov.
Four-time winners Barcelona face Benfica, Spartak Moscow and Celtic.
Manchester United, who failed to clear the group stage last season, also have a relatively weak group with Braga, Galatasaray and Cluj.
Here are the eight groups.
Group A FC Porto (Portugal), Dynamo Kiev (Ukraine), Paris Saint-Germain (France), Dinamo Zagreb (Croatia)
Group B Arsenal (England), Schalke (Germany), Olympiakos (Greece), Montpellier (France)
Group C AC Milan (Italy), Zenit St. Petersburg (Russia), Anderlecht (Belgium), Malaga (Spain)
Group D Real Madrid (Spain), Manchester City (England), Ajax (Netherlands), Borussia Dortmund (Germany)
Group E Chelsea (England), Shakhtar Donetsk (Ukraine), Juventus (Italy), Nordsjaelland (Denmark)
Group F Bayern Munich (Germany), Valencia (Spain), Lille (France), BATE Borisov (Belarus)
Group G Barcelona (Spain), Benfica (Portugal), Spartak Moscow (Russia), Glasgow Celtic (Scotland)
Group H Manchester United (England), Braga (Portugal), Galatasaray (Turkey), Cluj (Romania)