When a month is incomplete (29 days), the following Rosh Chodesh is one day. When it is full (30 days), the following Rosh Chodesh lasts two days, the first day being the thirtieth of the previous month, and the second day being the first of the next month. Even though the second day is the main part of Rosh Chodesh – seeing that it is the first day of the month, from which we count the subsequent days of the month – nevertheless, all the laws of Rosh Chodesh apply to the first day, as well. We add the Additional Musaf Prayer , we recite Hallel, and we insert Ya’aleh VeYavo into our Amidah Prayers and Grace After Meals. One who forgot to say Ya’aleh VeYavo in Shacharit or Minchah must repeat the Shemoneh Esrei. Several explanations have been given for the practice of keeping two days of Rosh Chodesh; see the footnote.
Seemingly, one could ask: Rosh Chodesh means the first day of month; why then is the thirtieth day of a full month also considered Rosh Chodesh? The Shibolei HaLeket (168) quoting Rabbeinu Shlomo and the Rid (the earlier R. Yeshayah), as well as the author of Birkei Yosef (427), explain that when a month is full, 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 – 1.1), nonetheless, it is fitting to also treat the day on which the moon reappears as Rosh Chodesh. This is why we keep two days of Rosh Chodesh.
The Tashbetz (3:244) writes that the Jews in ancient times used to refrain from work, and prepare festive meals in honor of Rosh Chodesh, and they would begin doing so already on the thirtieth day of the month, in the event that witnesses arrive and the Beit Din declares that day the first of the month. And if no one came to testify, they treated the next day as Rosh Chodesh as well. Thus, whenever a month was full, they kept two days of Rosh Chodesh (similar to Rosh HaShanah). Even though the Musaf sacrifices were offered up exclusively on the first of the month, these two explanations indicate that both days are holy, and we therefore say Hallel, Musaf, and Ya’aleh VeYavo on both days.
Rabbi Zevin writes in LeOr HaHalachah (in an essay on Rosh Chodesh) that according to Rashi and the Shiltei Giborim (Rosh HaShanah, chap. 1), Jews used to keep one day of Rosh Chodesh on a full month, while the Or Zarua (vol. 2, Hilchot Rosh Chodesh) and the Maharsha (Bava Metzia 59b) maintain that they kept two days.
These authorities also disagree on how to interpret a verse in the First Book of Shmuel (20:27): ויהי ממחרת החדש השני. The Tashbetz and Rabbeinu Yeshayah understand it as a reference to the second day of Rosh Chodesh, while Rashi, and the Radak, say that it refers to the day after Rosh Chodesh, a regular day.
Some say that we observe two days because we are unsure which day is truly Rosh Chodesh. This opinion, however, has been rejected. Therefore, one who forgets to recite Ya’aleh VeYavo in Shacharit or Minchah, on either day, must repeat the Shemoneh Esrei. See Sefer Rosh Chodesh, ch. 10, note 4.