Below, in Zeir Anpin, there are nine letters, from Yod (י) to Tzadi (צ). And in Malchut, there are four last letters: Kuf (ק), Resh (ר), Shin (ש) and Tav (ת).
This order derives from the Second Restriction (Tzimtzum Bet) when Malchut ascends exactly to ZAT de Bina (lower seven Sefirot of Bina), bringing her Kelim (desires, vessels) there, her will to receive. She cannot rise any higher. Consequently, the properties of Bina and Malchut, bestowal and reception, get mixed, thereby forming contours of letters. Mingling, the forces of Malchut and Bina get intertwined and create various forms of mutual inclusion, their combinations.
Why are there only 22 forms and not more? According to the laws of the Second Restriction, we employ not Malchut per se but only her connection with Bina. In Bina and Zeir Anpin, there are ten Sefirot, which Sefira Malchut is prohibited to use. Thus, all in all, they have 18 “workable” Sefirot. Besides, four Sefirot of Malchut clothe in Zeir Anpin, which totals 22.
Additionally, there are five forms, MaNTzePaCh, belonging to Parsa; they are different shapes of certain letters when they end a word. The entire process of letter formation takes place in the world of Atzilut, where they are called to perform bestowal to the world of BYA (Beria, Yetzira, Assiya) and the broken souls.
From the 1st part of the Daily Kabbalah Lesson 12/15/10, "Introduction from The Book of Zohar," Article “The Letters by Rabbi Amnon Saba”