There were four Sunni schools of fiqh (madhhabs) that began to evolve a few decades after the Prophet’s death. At that time, people needed well-qualified scholars to understand the texts and sources of Shari`ah and to explain its rulings to people. The differences among the imams were regarding the branches, not the primary sources, of Shari`ah.

The eminent Muslim scholar and renowned da`iyahSheikh `Abdel Khaliq Hasan Ash-Shareef states the following: In fact, these schools cannot be deemed as sub-sects of Islam. Imams Abu Hanifah, Malik, Shafi`i, and Ahmad were scholars who understood the religion and explained its rulings to people. They received knowledge from other scholars and, by the same token, they had students who received knowledge from them. With the passage of time, these scholars became famous among people for their knowledge.

The difference between the four imams has nothing to do with the principles of the Islamic creed or the essentials and the basics of the religion. Rather, their differences relate to the secondary issues and come as a result of the difference in understanding of the texts of the Shari`ah. Therefore, it is not strange that some of the followers of a certain imam may adopt the opinion of another imam.
None of the four imams was contemporary to the Prophet (peace and blessings be upon him). Indeed, the earliest of these imams, Abu Hanifah, was born 70 years after the Prophet’s death.
The differences between the imams regarding how to perform prayer do not affect the validity of your prayer; following any of them does not make your prayer invalid.