The Jewish calendar is based on solar years and lunar months. The lunar month, which begins at the new moon, is about
29-1/2 days long. Since a Jewish month must consist of an integer number of days, it can be either 29 or 30 days long.
Traditionally, the Sanhedrin proclaimed a new month after 29 days if witnesses testified that they had seen the new moon; if
there were no witnesses, the new month was proclaimed after 30 days.
A Jewish year must consist of an integer number of months (cf. the phrase "le-chodshei ha-shanah" in Ex. 12:2). Since 12
lunar months are about 10 days short of a solar year, a 13th month needs to be added every two or three years to keep the
Jewish year (approximately) in step with the solar year. Traditionally, the Sanhedrin proclaimed a 13-month year if they saw
that the month of Nisan would otherwise begin too early, i.e. before the equinox (the Torah calls it the "spring month" in Ex. 13:4).
The last President (Nasi) of the Sanhedrin was Hillel II. In his time (ca. 360 C.E.), because the Roman government was
making it difficult for the Sanhedrin to operate, he establish a fixed calendar which is essentially the one we use today, with
a fixed pattern of 12- and 13-month years (seven 13-month years, approximately evenly spaced, out of every 19 years) and
a fixed pattern of 29- and 30-day months in each year (arranged so that Yom Kippur does not fall on Friday or Sunday, and
Hoshana Rabbah does not fall on Shabbos).
Ask a follow-up question