Namaz-e-Ayat becomes obligatory due the following four things:
The prayer becomes Wajib even if the moon or the sun are partially eclipsed, and even if they do not engender any fear.
Earthquake, as an obligatory precaution, even if no one is frightened.
Thunder and lightning, red and black cyclone and other similar celestial phenomena, which frightens most of the people; similarly for the terrestrial events like receding sea water, or falling mountains which engender fear in these circumstances, as per recommended precaution, Namaz-e-Ayat be offered.
If several events which make Namaz-e-Ayat obligatory occur together, one should offer Namaz-e-Ayat for each of them. The time of Namaz-e-Ayat sets in as the eclipse starts, and remains till the eclipse is over.
Method of Offering Namaz-e-Ayat
Namaz-e-Ayat consists of two Rak'ats, and there are five Ruku' in each. Its method is as follows:
After making niyyat of offering the prayers, one should say takbir (Allahu Akbar) and recite Surah al-Hamd and the other Surah, and then perform the Ruku'. Thereafter, he should stand and recite Surah al-Hamd and a Surah and then perform another Ruku'. He should repeat this action five times, and, when he stands after the fifth Ruku', he should perform two Sajdah, and then stand up to perform the second Rak'at in the same manner as he has done in the first. Then he should recite tashahhud and Salam.
Namaz-e-Ayat can also be offered in the following manner:
After making niyyat to offer Namaz-e-Ayat, a person is allowed to say takbir and recite Surah al-Hamd and then divide the verses of the other Surah into five parts, and recite one verse or more or less and thereafter perform the Ruku'. He should then stand up and recite another part of the Surah (without reciting Surah al-Hamd) and then perform another Ruku'. He should repeat this action, and finish that Surah before performing the fifth Ruku'. For example, he may say: Bismillahir Rahmanir Rahim with the niyyat of reciting Surah al-Ikhlas, and perform the Ruku'. He should then stand up and say, Qul huwallahu Ahad, and perform another Ruku'. He should then stand up and say, Allahus Samad, and perform the third Ruku'. Thereafter he should stand up again and say, Lam yalid walam yulad, and perform the fourth Ruku'. Then he should stand up again and say, Walam yakun lahu Kufuwan ahad, and then perform two Sajdah and then rise for the second Rak'at, the same way as the first Rak'at. At the end, he should recite tashahhud and Salam after the two Sajdah.
source : tebyan