The Hanafi (Arabic: حنفي Ḥanafī) school is one of the four religious Sunni Islamic schools of jurisprudence (fiqh). It is named after the scholar Abū Ḥanīfa an-Nu‘man ibn Thābit (d. 767), a tabi‘i whose legal views were preserved primarily by his two most important disciples, Abu Yusuf and Muhammad al-Shaybani. The other major schools of Sharia in Sunni Islam are Maliki, Shafi'i and Hanbali.
Hanafi is the fiqh with the largest number of followers among Sunni Muslims. It is predominant in the countries that were once part of the historic Ottoman Empire, Mughal Empire and Sultanates of Turkic rulers in the Indian subcontinent, northwest China and Central Asia. In the modern era, Hanafi is prevalent in the following regions: Turkey, the Balkans, Syria, Lebanon, Jordan, Palestine, Egypt, parts of Iraq, the Caucasus, parts of Russia, Turkmenistan, Kazakhstan, Kyrgyzstan, Tajikistan, Uzbekistan, Afghanistan, Pakistan, parts of India and China, and Bangladesh.
As the fourth Caliph, Ali had transferred the Islamic capital to Kufa, and many of the first generation of Muslims had settled there, the Hanafi school of law based many of its rulings on the earliest Islamic traditions as transmitted by Sahaba residing in Iraq. Thus, the Hanafi school came to be known as the Kufan or Iraqi school in earlier times. Ali and Abdullah, son of Masud formed much of the base of the school, as well as other personalities such as Muhammad al-Baqir, Ja'far al-Sadiq, and Zayd ibn Ali. Many jurists and historians had lived in Kufa including one of Abu Hanifa's main teachers, Hammad ibn Sulayman.
In the early history of Islam, Hanafi doctrine was not fully compiled. The fiqh was fully compiled and documented in the 11th century.
The Turkish rulers were some of the earliest adopters of relatively more flexible Hanafi fiqh, and preferred it over the traditionalist Medina-based fiqhs which favored correlating all laws to Quran and Hadiths and disfavored Islamic law based on discretion of jurists. The Abbasids patronized the Hanafi school from the 10th century onwards. The Seljuk Turkish dynasties of 11th and 12th centuries, followed by Ottomans adopted Hanafi fiqh. The Turkic expansion spread Hanafi fiqh through Central Asia and into South Asia, with the establishment of Seljuk Empire, Timurid dynasty, Khanates and Delhi Sultanate.