On an August morning in 2014, someone noticed a black flag hanging outside a rundown duplex in suburban New Jersey. He could not make out its Arabic, but he recognized the design from horrific news reports about ISIS, in which masked jihadists fought under the banner to realize their dark vision of God’s rule on earth. Alarmed, the passerby sent a picture of the house and its flag to a friend, who promptly tweeted it and informed the Department of Homeland Security.

The flag’s owner, Mark Dunaway, had converted to Islam a decade prior, he explained to the police when they arrived, and he flew the flag to mark Muslim holidays. “Every Muslim uses that black flag,” he said. “You’ll find it in any mosque in the world.” Still, he took it down. “I understand now that people turn on CNN and see the flag associated with jihad, but that’s not the intention … at all. It says, ‘There is only one god, Allah, and the prophet Mohammed is his messenger.’ It’s not meant to be a symbol of hate.” Dunaway, like many Muslims and even Middle East experts, did not know that the flag had been designed by ISIS in 2006. He and others were confused because the Islamic State had used terror and Twitter to advertise its brand, and Islamic tradition to obscure its meaning.

Before the group declared itself the caliphate reborn that summer, it had been ambiguous about the flag’s meaning and the cause it represented. Was it the flag of an Islamic state, or the flag of the Islamic state—the caliphate that had once ruled land from Spain to Iran and whose prophesied return would herald the end of the world? The Islamic State encouraged the second interpretation but let the global community of jihadists read into the flag and the “state” what they would. The group’s cause proved so compelling among jihadists that in 2014 the organization supplanted its former master, al-Qaeda. The spread of the flag, then, traces the spread of an idea and chronicles a major changing of the guard in the global jihadist movement.

ISIS Flag (Wikimedia)

When the Islamic State first announced itself on October 15, 2006, it had no flag of its own. It was not until January 2007 that al-Qaeda’s media distribution arm, al-Fajr, released a picture of the Islamic State’s new flag. Anonymous authors affiliated with the Islamic State explained its design, quoting passages from Islamic scripture and historical accounts. “The flag of the prophet, peace and blessings be upon him, is a black square made of striped wool,” according to one account. Another describes Mohammed “standing on the pulpit preaching” surrounded by fluttering black flags. “On the flag of the prophet was written, ‘No god but God, and Mohammed is the Messenger of God.’” The flag even had a name: “the eagle.”

Although the authors acknowledged other reports of green, white, and yellow flags, they concluded the Islamic State’s flag would be black, because most of the reports about Mohammed mentioned a black flag. The authors were equally confident when explaining the banner’s text. “What is written on the flag is what is written on the flag of the Messenger of God, peace and blessings be upon him.”

The Islamic State’s design of the Muslim profession of faith is different from every other attempt to replicate the prophet’s flag: “No god but God” is scrawled in white across the top and “Mohammed is the Messenger of God” is stacked in black inside a white circle. As the anonymous authors noted, they took the circle’s design from a seal of the prophet used on a set of letters, now housed in Turkey’s Topkapi Palace, that were supposedly written on Mohammed’s behalf. (Modern scholars doubt the letters’ authenticity.) We are meant to believe the Islamic State had inherited the prophet’s seal, just as the early caliphs had.

Why make a flag? In addition to following the prophet’s example, the Islamic State wanted a symbol to rally people to its cause. The group quoted a 19th-century Ottoman historian and official, Ahmad Cevdet Pasha, to make the point:

The secret in creating a flag is that it gathers people under a single banner to unify them, meaning that this flag is a sign of the coming together of their words and a proof of the unity of their hearts. They are like a single body and what knits them together is stronger than the bond of blood relatives.

Yet the Islamic State’s choices display the modern sensibilities they try so hard to displace. The white scrawl across the top, “No god but God,” is deliberately ragged, meant to suggest an era before the precision of Photoshop, even though the flag was designed on a computer. Even the Islamic State’s quotation of Ahmad Cevdet Pasha unwittingly betrays a modern perspective. Influenced by European notions of nationalism yet desiring to hold together the multiethnic Ottoman Empire under sovereign Turkish rule, Cevdet Pasha imagined Islam and its symbols to be the glue. “The only thing uniting Arab, Kurd, Albanian, and Bosnian is the unity of Islam,” he said, according to Dominic Lieven’s book Empire: The Russian Empire and its Rivals. “Yet the real strength of the Sublime State lies with the Turks.”

The Islamic State ended the explanation of its flag’s design with a prayer: “We ask God, praised be He, to make this flag the sole flag for all Muslims. We are certain that it will be the flag of the people of Iraq when they go to aid … the Mahdi at the holy house of God.” The house of God is the Kaaba in Mecca, the holiest shrine in Islam, and the Mahdi is the savior who Muslims believe will appear there in the years leading up to the apocalypse. The Islamic State was signaling that its flag was not only the symbol of its government and the herald of a future caliphate; it was the harbinger of the final battle at the End of Days.

* * *

Legends of the black flag and the Muslim savior, the Mahdi, first circulated during the reign of the Umayyad dynasty, which ruled the Islamic empire from Damascus in the seventh and eighth centuries C.E. The dynasty’s founders, the Umayya clan, had seized the caliphate from Mohammed’s son-in-law and grandsons, which infuriated many Muslims. People unhappy with Umayyad rule circulated prophecies of a man of the prophet’s family who would return justice to the world. They called the man the Mahdi, Arabic for “the Rightly Guided One.” Many of the prophecies envision the Mahdi appearing during the End of Days to lead the final battles against the infidels.

Like most Islamic prophecies of the End of Days, those about the Mahdi are not found in the preeminent scripture of Islam, the Koran, which Muslims believe preserves God’s revelation to Mohammed, but rather in the voluminous compendia of the words and deeds of the prophet and his companions, known as hadith, which were written down decades or even centuries after the prophet’s death. Muslims argue over the veracity of individual hadith, and the contradictions between them, the way some Christians debate the reliability of the Gospels and their discrepancies.

End-Time prophecies were an especially inviting target for fabricators. In the internecine wars that tore apart the early Muslim community, each side sought to justify its politics by predicting its inevitable victory and the other side’s preordained defeat. Prophecies proliferated, reaching into the thousands. When the politics evaporated, the prophetic residue remained.

Supporters of the prophet’s family loosely aligned themselves as part of what historians call the Hashemite movement, which believed the Mahdi would be a descendent of Mohammed’s great-grandfather, Hashem. Many of the movement’s supporters were from Iran, where Zoroastrian legends prophesied the coming of a club-wielding savior who would appear at the End of Time followed by sable-clad disciples. Influenced by the prophecies, the revolutionaries donned black clothes, flew black flags, and carried around wooden clubs called “infidel-bashers.”

As the revolutionaries built support for their cause, they circulated prophecies of soldiers fighting under black flags who would come from the East to overthrow the Umayyads. Some were put in the mouth of Mohammed’s son-in-law, Ali, who allegedly foretold the coming of an army from Khorasan, the “land of the rising sun” that includes parts of eastern Iran and most of Afghanistan. Other black-flag prophecies were attributed to the prophet himself. “If you see the black banners coming from Khorasan,” instructs one, “go to them immediately even if you must crawl over ice because indeed among them is the caliph, al-Mahdi.”

In early Islam, the color black was associated not just with mourning but also with revenge for a wrongful death. According to the historian Ibn Khaldun, the opponents of the Umayyads adopted black as their color to avenge the Umayyads’ persecution of the prophet’s family. Black flags were also flown by the prophet in his war with the infidels. “Do not flee with [the flag] from the infidels and do not fight with it against the Muslims,” Mohammed reportedly told one of his generals.

Apocalyptic messages resonate among many Muslims today because of the political turmoil in the Middle East. In 2012, half of all Muslims in North Africa, the Middle East, and South Asia expected the imminent appearance of the Mahdi. And why wouldn’t they, given the revolutions sweeping the Arab world? The signs that herald his coming have only multiplied since. A great sectarian war tears Syria asunder. Iraq is in chaos. The “infidel” West has invaded. The “tribulations” are too awful and apparent to brook mundane explanations.

This article has been adapted from William McCants’s new book, The ISIS Apocalypse: The History, Strategy, and Doomsday Vision of the Islamic State.