Barcelona will begin their defence of the Copa del Rey with a two-legged clash against Segunda B side Hercules.
The Spanish champions, who overcame Sevilla in the 2016 final to win the competition for a 28th time, will travel to Hercules for the first leg on November 30, before the return match takes place on December 21.
Real Madrid, meanwhile, have been drawn with Segunda B side Cultural Leonesa in the fourth round - 56 years after their first and only previous meeting, which was a 9-0 victory for the Madrid giants.
Elsewhere, Sevilla will take on fourth-tier outfit SD Formentera, while Atletico Madrid have been drawn with CD Guijuelo, who also play their football in the Segunda B Division.
Copa del Rey fourth-round draw in full:
Alcorcon vs. Espanyol
Cordoba vs. Malaga
Cultural Leonesa vs. Real Madrid
Formentera vs. Sevilla
Gimnastic vs. Alaves
Granada vs. Osasuna
Guijuelo vs. Atletico Madrid
Hercules vs. Barcelona
Huesca vs. Las Palmas
Leganes vs. Valencia
Racing Santander vs. Athletic Club Bilbao
Real Betis vs. Deportivo La Coruna
Real Valladolid vs. Real Sociedad
Sporting Gijon vs. Eibar
UCAM Murcia vs. Celta Vigo
Villarreal vs. Toledo