So a shia said their belief has always been about 12 imam, but in reality, the idea of who would be the mahdi were not so clear by imam's followers, let alone the no 12.
The confusion happened after every imam died. Fortunately all this was recorded by a 3rd century shia scholar al-Hasan bin Musa al-Nawbakhti in his book Firaq al-Shia. It all started after Ali's death and it is repeated everytime an imam passed away. When the 11th imam died, his followers were divided into 14 different groups, each one has their own unique opinions.
Luckily for shia, several centuries later under the iron fist of bloodthirsty Savafid dynasty, eventually the shia 12er belief reign supreme and became the most powerful of all shia sects.
Let's see some of the examples of the different imam & mahdi that followers of imam believed from Ali RA until Hasan al-Askari
1. Ali is Mahdi
“….Ali was not killed and he did not die. They said that he would not die until he has driven the Arabs with his cane and filled the earth with justice and fairness after it has been filled with oppression and injustice. This was the first sect in Islam which believed in waqf (imamate ended with Ali as hidden imam) after Rasulullah. They are also the first extremists. They are called Saba’iyyah, the follower of Abdullah bin Saba’ who publicly criticised Abu Bakar, Umar…“
“…some scholars who were close to Ali (AS) said that Abdullah bin Saba’ was a Jew before he converted to Islam…”
“….he (Abdullah bin Saba’) was the first to declare that the imamate of Ali (AS) was mandatory…”
[The first people who hated Abu Bakar & Umar (ra) were the followers of Abdullah bin Saba the Jew, the same person whose existence many Shias of today try to deny]
2. Muhammad bin al Hanafiyya is Mahdi
“….they said al Hasan bin Ali went to war against Mu’awiyah with the permission of Muhammad and made treaty also with his permission. al Husein also, they said, fought Yazid with his permission, if not, both of them (al Hasan & al Husein) will be astray and ruined…”
[Hasan & Husein are followers of the true imam, Muhammad al-Hanafiyah]
3. Abdullah bin Muhammad bin al Hanafiyya (Abu Hashim) is Mahdi
“….he is called Abu Hashim and he is his father's eldest son. His father appointed him as his successor….he is al Mahdi and he did not die….”
[Muhammad al-Hanafiyah's son, not Hasan nor Husein as the next imam & Mahdi]
4. Abdullah bin Mu’awiyah bin Abdullah bin Ja’far bin Abi Talib (appointed by Abu Hashim) is Mahdi
“….Abdullah bin Mu’awiyah is al Mahdi, who was mentioned by Rasulullah and his Ahlulbait and he will lead the world, to fill it with goodness and justice after it was filled with injustice and oppression. Then, when he died, he will leave his position to someone from Bani Hashim – from the descendant of Ali bin Abi Talib….”
[Mahdi is from Ja'far bin Abi Talib's lineage, not Ali's]
5. Muhammad bin Abdullah bin al Hasan (al-Mutsanna) bin al Hasan bin Ali bin Abi Talib is Mahdi (known as an-Nafs az-Zakiya)
“When Abu Ja’far (AS) dies, his followers were divided into 2 groups. The first believed in the imamate of Muhammad bin Abdullah bin al Hasan bin al Hasan bin Ali bin Abi Talib who revolted in Madina and was killed there. He claimed that he was al Mahdi and he did not die….”
[Mahdi is Hasan's progeny not Husayn's]
6. Ja’far al-Sadiq is Mahdi
“Ja’far bin Muhammad did not die and he will not die until he revolts and rule the people and he is al-Mahdi….”
[Ja’far al-Sadiq is Mahdi, however after his death the majority of Shia's scholars & respected figures believed in Abdullah, not Musa al-Kadhim as the next imam. After Abdullah died, they then followed Musa al-Kazim. Whatever happened to the so called hadith which mentioned all the 12 imam by names, did those shia scholars could not tell the difference between the name Abdullah & Musa?]
7. Ismail bin Ja’far al-Sadiq is Mahdi
“….they denied the death of Ismail during his father's life – saying it was a trick plotted by his father, who was afraid for him, so he hid him. They claimed Ismail would not die until he ruled the world and cared for the people and that he was al-Mahdi, because his father appointed him for the imamate after him….”
[The true imam was Ismail not Musa al-Kadhim]
8. Muhammad bin Ismail bin Ja’far al Sadiq is Mahdi
“….There were only 7 imam after Rasulullah and his Ahlulbait. They were Ali bin Abi Talib, al-Hasan, al-Husein, Ali bin al-Husein, Muhammad bin Ali, Ja’far bin Muhammad, Muhammad bin Ismail bin Ja’far, who was al-Qaim al-Mahdi….”
[True imam were only 7 not 12]
9. Musa al Kadhim is Mahdi
“….Musa bin Ja’far did not die, nor will he die until he rules the world from east to west. He would fill it with justice after it had been filled with oppression. They claimed that he was al-Qaim al-Mahdi….”
[Imamate ended with al-Kadhim, did not continue after him. Ali al-Ridha and others after him were only al-Kadhim's deputies, not true imam]
10. Muhammad bin Ali bin Muhammad bin Ali bin Musa is Mahdi
“….when Ali bin Muhammad bin Ali bin Musa al-Ridha (AS) died, a group from his followers believed in the imamate of his son, Muhammad, who died in Samarra during his father's life…They claimed that he was al-Mahdi….”
[Ali al-Hadi/al-Naqi appointed Muhammad (who was made to appear to die during his lifetime) as the next imam & also Mahdi, not Hasan al-Askari]
11. Hasan bin Ali al-Askari is Mahdi
“….his followers became fourteen 14 groups after his death. One group said that al-Hasan bin Ali is alive, but he dissapeared and he is al-Mahdi, for it is impossible for him to die not leaving an acknowledged son….”
[This is one of the most confusing death as his followers were divided into this many groups]
And we still hear shia said that their imamate belief is as clear as the sun. The belief which suppose to prevent the them from misguidance became the doctrine which misguide and confused shia, even their scholars during their imam's life.