The Tur (581) quotes the Pirkei D’Rebbi Eliezer (Perek 46) who says: On Rosh Chodesh Elul, Hakadosh Boruch Hu said to Moshe “Ascend up to Me on the mountain”. At that time Moshe ascended the mountain to receive the second set of Luchos. At that time the sound of the shofar was sounded in the camps, and Hakadosh Boruch Hu was very impressed with the shofar (עלה אלוקים בתרועה), therefore, Chazal fixed that every year we blow shofar on Rosh Chodesh, for the entire month.
The Magen Avraham (581:2) cites a machlokes haposkim as to when we start blowing shofar. On one side the Levush, Maharshal, Masas Binyomim, Shlah and Maharil all say that we start on first day Rosh Chodesh, as the reason for blowing shofar is to sort of reenact the shofar blowing that happened when Moshe Rabbeinu ascended the mountain, and that happened 40 days before Yom Kippur which was the first day of Rosh Chodesh Elul. This is also the opinion of the Da’as Zekeinim MiBaalei HaTosfos (Eikev 10:10).
The Magen Avraham then brings, that some argue and learn that we start on the second day of Rosh Chodesh. The Magen Avraham quotes the Mateh Moshe (778) who says: Since we blow for thirty days, we start on the first day of Elul, which is the second day of Rosh Chodesh, and since we don’t blow on erev Rosh Hashanah, it comes out that we blow on twenty eight days in Elul, together with the two days of Rosh Hashanah which totals thirty.
The Magen Avraham adds: Moshe Rabbeinu ascended the mountain on the second day of Rosh Chodesh, however, that year Elul was a full month, so it comes out there were forty days until Yom Kippur, therefore, today we also start on second day Rosh Chodesh, even though for us Elul is not a full month and is only twenty-nine days.
Halachah lemaaseh, the Magen Avraham rules that we start blowing on second day Rosh Chodesh, and one shouldn’t differ from this custom.