Carlo Ancelotti's Madrid were drawn to face minnows Olimpic Xativa in the last 32 of the competition, while on the other side of the draw Barcelona will play Cartagena. The matches are to be played over two legs, on December 7/8 and December 18.
Madrid and Olimpic Xativa share a former coach, with current Canada boss Benito Floro having been in charge both at the La Murta stadium and the Bernabeu earlier in his career, but there are few other similarities.
Olimpic Xativa play in Group 3 of the Segunda Division B, and their basic stadium houses just 9,000 spectators.
Cartagena sit second in Group 4 of the Segunda Division B, with the club having been founded as recently as 1995.
Another daunting obstacle for Madrid is a potential semi-final against Atletico Madrid, the team they were beaten by in last season's Copa del Rey final.
This year's final takes place on April 19.
Copa del Rey third-round draw (draw stays in formation throughout the competition):
1. Real Valladolid v Rayo Vallecano
2. Recreativo Huelva v Levante
3. Cartagena v Barcelona
4. Girona v Getafe
5. Algeciras v Real Sociedad
6. Villarreal v Elche
7. Las Palmas v Almeria
8. Real Racing Club v Sevilla
9. Alcorcon v Granada
10. Real Jaen v Espanyol
11. Olimpic Xativa v Real Madrid
12. Malaga v Osasuna
13. Gimnastic de Tarragona v Valencia
14. Sant Andreu v Atletico Madrid
15. Lleida v Real Betis
16. Celta Vigo v Athletic Bilbao