During the long period in antiquity when the Hebrew calendar was established by the court based on the testimony of witnesses who had seen the new moon, the addition of an extra day to a month was determined by their testimony. If the moon was sighted on the night after the twenty-ninth day of the month, the next day was the first day of the following month. If, however, the moon was not sighted that night, or if witnesses to the new moon did not appear in Jerusalem to testify the following day, an extra day was added to the previous month, giving it thirty days. In that case, both the thirtieth and the thirty-first day were treated as the New Moon. Since the fourth century C.E., the Jewish calendar has operated on a fixed astronomical system in which, generally, months of twenty-nine days alternate with those of thirty days.
The Jewish calendar is based on lunar months – 12 per year – all told 354 days per year (occasionally there is a need to add a full extra month in order to match the lunar calendar with the solar calendar, which is 11 days longer). Since the lunar month is approximately 29 and a half days long, and we count a month of full days, in order to reach 354 days we must have six 29-day months and six 30-day months.
In theory, we should be able to establish a set calendar with alternating 29 and 30 day months. Nevertheless, since every month is a little longer than 29 and a half days (793 out of 1080 parts of an hour, to be precise) the additional time adds up so that we will need to add a day or two, and, occasionally, additions made one year will force the shortening of the following year. In addition, the Sages had the ability to establish whether a given month would be 29 or 30 days long, depending on a number of factors. For example, the Sages manipulated the calendar so that Yom Kippur will not fall out on a Friday or so that Hoshana Rabba will not fall out on Shabbat.