The members are suspected of links to the Islamic State (IS) group, also known as Daesh.
Police have questioned 25 prisoners who are “accused of being part of a group close to Daesh which was dedicated to radicalising other prisoners,” the interior ministry said in a statement.
Gracias al trabajo conjunto de @guardiacivil y funcionarios de #InstitucionesPenitenciarias se ha desarticulado un grupo afín a #DAESH asentado en cárceles españolas acusado de captar, adoctrinar y radicalizar a otros presos.
Más info ?https://t.co/jopoQKNSyx pic.twitter.com/6rf5okMyHl
— Ministerio Interior (@interiorgob) October 2, 2018
Most were Moroccans, or Spanish nationals of Moroccan origin, a Spanish anti-terrorism source told AFP. One was a Danish national and the rest were Spanish nationals who had converted to Islam.
Two of them were sentenced to jail in 2007 for their roles in the 2004 Madrid train bombings, the anti-terrorism source said.
Those attacks killed 191 people and injured over 1,800 others. It was Europe's worst jihadist attack.
The ring sought to unite prisoners jailed for terrorist crimes in a so-called “Prison Front”.
The anti-terrorism source said the ring did not have a “concrete plan” to carry out an attack but created a “belligerent state of mind towards prison staff”.
Some of the members of the group were to be released from prison soon.
International studies show that prison radicalisation is a problem in various countries including Britain and the United States.
Sixteen people were killed on August 17, 2017 when a van drove into crowds on Barcelona's popular Las Ramblas boulevard and in a knife attack in the nearby resort of Cambrils.
The Islamic State group claimed responsibility for those attacks, Spain's worst since 2004.