When a month is incomplete (29 days), the following Rosh Ĥodesh is observed for one day. When it is full (thirty days), the following Rosh Ĥodesh lasts two days: the thirtieth day of the previous month and the first day of the next month. Even though the second day is the main part of Rosh Ĥodesh – as it is the first day of the month, from which we count the subsequent days of the month – nevertheless, all the laws of Rosh Ĥodesh apply to the first day as well. We recite the Hallel and Musaf prayers and we insert Ya’aleh Ve-yavo into the Amida (the silent standing prayer, i.e., Shemoneh Esrei) and Birkat Ha-mazon (Grace after Meals). One who forgot to recite Ya’aleh Ve-yavo in Shaĥarit or Minĥa must repeat the Amida. Several explanations have been given for the practice of observing two days of Rosh Ĥodesh; see the footnote.
 Rosh Ĥodesh means the first day of month; why then is the thirtieth day of a full month also considered Rosh Ĥodesh? Shibolei Ha-leket 168, quoting Rabbeinu Shlomo and Rid, as well as Birkei Yosef 427, explain that on a full month, the new moon appears in the middle of the thirtieth day (after 29½ days). Therefore, even though the next day will be the first of the month (in order to balance out the months, as explained above, in section 1), nonetheless, it is fitting to treat the day on which the moon reappears as Rosh Ĥodesh as well. This is why we observe two days of Rosh Ĥodesh.
Tashbetz 3:244 states that the Jews in ancient times would refrain from working and prepare festive meals in honor of Rosh Ĥodesh, already beginning to do so on the thirtieth day of the month, in case witnesses arrive and the beit din declares that day the first of the month. And if no one came to testify, they would treat the next day as Rosh Ĥodesh as well. Thus, whenever a month was full, they observed two days of Rosh Ĥodesh (similar to Rosh Ha-shana).
Even though the musaf sacrifices were offered exclusively on the first of the month, these two explanations indicate that both days are holy, and we therefore recite Hallel, Musaf, and Ya’aleh Ve-yavo on both days.
R. Shlomo Yosef Zevin writes in Le-or Ha-halakha (in an essay on Rosh Ĥodesh) that according to Rashi and Shiltei Giborim (Rosh Ha-shana, ch. 1), Jews used to observe only one day of Rosh Ĥodesh for a full month, while Or Zaru’a (vol. 2, Hilkhot Rosh Ĥodesh) and Maharsha (BM 59b) maintain that they observed two days.
These authorities also disagree how to interpret the verse, "But on the day after the new moon, the second day" (1 Shmuel 20:27). Tashbetz and Rabbeinu Yeshaya understand it as a reference to the second day of Rosh Ĥodesh, while Rashi and Radak maintain that it refers to the day after Rosh Ĥodesh – a regular day.
Some explain that we observe two days because we are uncertain which day is truly Rosh Ĥodesh. This opinion, however, has been rejected. Therefore, one who forgets to recite Ya’aleh Ve-yavo in Shaĥarit or Minĥa on either day must repeat the Amida.