Defending champions Real were paired with Borussia Dortmund in Group F alongside Portugal's Sporting and Legia Warsaw of Poland in the group stages draw.
Pep Guardiola will return to the Nou Camp in the Champions League group stage after his new club Manchester City were drawn against his former Barcelona team on Thursday in one of the toughest of the eight groups.
Bayern Munich were given a quick chance to avenge last season's semi-final defeat by Atletico Madrid after they were drawn together while English Premier League winners Leicester City will face Porto, Club Bruges and Copenhagen on their debut.
Elsewhere, holders and 11-times champions Real Madrid renew their recent rivalry with Borussia Dortmund.
Barca and City were drawn in Group C alongside Borussia Moenchengladbach and former European champions Celtic, with recent history clearly favouring the Catalans.
Spanish coach Guardiola, who won the Champions League twice with Barca, suffered a 5-3 aggregate defeat when he faced his old team with Bayern in the semi-finals two seasons ago.
City, who visit the Nou Camp on October 19, met Barca in the round of 16 in 2013-14 and 2014-15 and lost both legs on each occasion.
Bayern, now under triple Champions League winner Carlo Ancelotti, and Atletico are clear favourites to progress from Group D which also features PSV Eindhoven and Russian league runners-up Rostov who are also group-stage debutants.
Ancelotti was cautious, however, pointing out that Atletico needed a penalty shootout to beat PSV last season and that Rostov eliminated Ajax Amsterdam in the playoffs this week.
"It's a difficult draw and we have to be careful," he said.
Real and Dortmund should go through from Group F at the expense of Sporting and Legia Warsaw, who are back in the group stage after a 20-year absence.
Dortmund knocked out Real in the semi-finals in 2013 but the Spanish giants came out on top the following season in the last eight.
"It's difficult but attractive. Matches against Real are becoming classics for Dortmund. We are looking forward to meeting the holders," said Dortmund coach Thomas Tuchel.
Apart from the odd heavyweight clash, many of the groups look predictable, a criticism that has increasingly been levelled at the competition in recent years.
Leicester, the other newcomers among the 32 teams, and Porto will start as favourites in Group G even though the English side are taking part for the first time.
Porto are in the group stage for the 21st time, a record they share with Real and Barca, but the double champions from Portugal have won only three of their last 16 ties against English teams in the competition.
Paris St Germain and Arsenal, who are attempting to reach the round of 16 for the 17th time in a row, are the favourites in Group A against Basel and rank Bulgarian outsiders Ludogorets although the Swiss have caused upsets in the past.
Juventus, Serie A winners for the last five seasons, face Sevilla, Olympique Lyonnais and Dinamo Zagreb in Group H with the first three likely to battle for the top two places.
For the third season running Serie A has only two teams in the group stage. The other side, Napoli, will meet Benfica, Besiktas and Dynamo Kiev in Group B.
Group E is arguably the most evenly-balanced with CSKA Moscow, Bayer Leverkusen, Tottenham Hotspur and Monaco.
It has been widely reported in the media that organisers UEFA, under pressure from the big clubs to reform the competition, will change the format from 2018-19 to allow four guaranteed places for England, Spain, Italy and Germany.
UEFA, which has faced talk of a breakaway Super League, has said only that it is studying possible changes for the 2018-21 cycle.