The four - three Spaniards and one Moroccan - were "willing to commit terrorist acts on Spanish soil," police said, adding they had allegedly made contacts to acquire weapons and substances used to make explosives.
They were detained in Spain's north African exclave of Ceuta and the Moroccan city of Nador, and police said the brother of one of the cell members had committed a suicide attack in Syria for the Islamic State group (IS).
"One of the leaders of the cell received military and combat training in camps in Afghanistan under the authority of terrorist jihadist organisations," police added.
"In 2002 he was detained and later put in the Guantanamo detention camp.
"The fact that this leader was trained in handling weapons, explosives and in military tactics makes this cell particularly dangerous."
Police said the main aim of the cell was to recruit people for IS, particularly minors.
It had put in place strict measures to avoid being caught - their meetings were held at dawn, telephone conversations were banned and messages encrypted.
Spain was the victim of the deadliest jihadist attack ever committed in Europe in March 2004 when train bombings killed 191 people in Madrid.
So far however it counts under 200 Spanish jihadist fighters within IS ranks, far fewer than neighbouring France for instance.