The most basic definition of the length of the month is the amount of time that it takes for the Moon's phases to complete one cycle, from new moon back to new moon again.
Since ancient times, this has been a very important cycle. Before the advent of street lighting, the Moon was the only easily-available and abundant source of lighting after nightfall.
The Moon's phases cycle on average once every 29.530589 days – once every synodic month. And here lies a problem: there are not an integer number of days in a month, and there are not an integer number of months in a year.
Devising a calendar in which there are an integer number of days in each month, and an integer number of months in each year is not easy.
The familiar western calendar of twelve months has a fixed pattern of either 365 or 366 days in each year. Leap years occur in roughly every fourth year, giving each year an average length of 365.2425 days. This closely matches the period of time over which the Earth's seasons repeat, the tropical year of 365.2422 days. The mismatch is such that the Earth's seasons drift later in the year by only 26 seconds each year.
By contrast, the months in our calendar comprise varying numbers of days between 28 and 31 in an ad hoc pattern.
This is what's called a solar calendar. The years keep in step with the Earth's seasons, but the months do not keep step with the Moon's phases. They are arbitrary divisions of each year into twelve unequal pieces.
The Moon completes twelve cycles of its phases every 354.37 days, some 11 days short of the length of year, meaning that in consecutive years, the full moons fall roughly 11 days earlier in each month.
Just as a solar calendar is one in which the years keep track of the Earth's seasons, so a lunar calendar is one in which the month's keep track of the Moon's phases.
One example of such a calendar is the Islamic calendar, in which months are defined to start and end at every new moon. Each year comprises of exactly twelve months, with an average length of 354.37 days.
This means that years in the Islamic calendar do not stay synchronised with the Earth's seasons. The seasons fall roughly 11 days later in the calendar each year.
Some calendars are more complicated still, and try to keep track of both the Moon's phases and the seasons.
One example is the Hebrew / Jewish calendar. Just as in the Islamic calendar, the months are defined to start and end at every new moon.
The difference is that years in the Jewish calendar can have either 12 or 13 months. Whenever the seasons move too far forward in the year, an extra intercalary month is inserted into the calendar to push them back to their rightful places.
In the fifth century BC, the Greek astronomer Meton of Athens observed that the duration of 19 years very closely equals 235 synodic months. This means that seven intercalary months need to be inserted into the Jewish calendar every 19 years.
Other kinds of months
The Moon's cycle of phases are not the only way that the month can be defined.
For example, the Moon circles the Earth once every 27.321661 – each sidereal month. This is a slightly shorter period of time than a synodic month, because the Sun is continuously moving across the sky, completing one complete revolution around the celestial sphere each year. This means that it moves by 30° across the sky each month, and to get from one new moon to the next the Moon must do more than complete one full revolution around the Earth: it must also cover this additional 30° to catch up with the Sun once again.
The Moon's orbit is slightly oval-shaped, and this means that its distance from the Earth varies by 13% over the course of each month. The period between its close approaches to the Earth is yet another time period still: 27.212220 days, or one draconic month.
The draconic month would be the same period of time as a sidereal month if the Moon traced out exactly the same path around the Earth on each orbit. However, in practice, the point where the Moon passes perihelion on each orbit precesses around the Earth with a nine-year period due to the perturbing effect of the Sun's gravity on the Moon's orbit around the Earth.