The difference is that 27 days is a SIDEREAL month, that is measured with respect to the stars. There are 29 days in a SOLAR month, measured with respect to the sun. Since the earth moves in its orbit over the period of a month, the sun moves with respect to the stars, thus the sidereal month differs from the solar month.
A solar month can be taken to mean 1 / 12th of a solar year. Then the mean-intercalary-month-period can be calculated by a formula much like that given by Janus. In other words, how long does it take for the ( shorter ) synodic month to take a lap on the ( longer ) solar month? This would be the "blue moon" period. It's about 33 or 34 months. These notions are important in luni-solar calendars that require a 13th month added to an otherwise 12 synodic month year.
If you take an earth day as a unit, then the moon cycles the earth at period of 27.5 day, in turn, the earth cycles the sun at 366,2425 day and at the same direction. So relatively, the moon cycles the earth (consider the earth as a frame) at the period of :
w=w1-w2 where w1 = 1/27.5 and w2 = 1/365.2425 (w, w1 and w2 = angular velocities)
So T = 1/w = ~29.5 days.