The 180 day calculation is on the basis of a sliding window. First, ignore any days when you were in Germany on your German residence permit. Then, for each day you're in the Schengen area, look at the 179 preceding days. If you were in the Schengen area for more than 89 of those days, you've been in the Schengen area too long.
Therefore, assuming your residence permit lasted longer than 90 days, which I think it must have, you needn't worry about the time you spent in Germany before it became valid. You might have to worry about days you spent in other Schengen countries, if you did in fact do that.
Furthermore, the consensus here seems to be that you don't need to leave the Schengen area to "start" your stay as a tourist. It just starts automatically at midnight on the day after your residence permit's expiration. If I recall correctly, however, there was one person who posted saying that German authorities had said he or she would need to leave the Schengen area, so you might want to do it anyway just to be on the safe side.
A strict reading of the Schengen codes, however, supports the conclusion that you don't need to leave. The Schengen Borders Code is available at http://eur-lex.europa.eu/legal-content/EN/TXT/?uri=celex:32016R0399.
By way of illustration, assume your permit expires on June 30th, having become effective on March 31st. Assume further that you didn't go to any other Schengen states during that time. On July 1st, you will look at the 180-day period that started on January 4th. Let's say you arrived on January 2nd, so you were present without a visa or permit from that day until March 30th, or 89 days. On July 1st, your total day count is 1 (for July 1st) plus 87 (for January 4th through March 30th).
With each successive day, the counted days in your current period increase, while the counted days in your prior period decreas: 2 + 86, 3 + 85, etc. But the sum is always the same: 88.
Once you reach September 26th, the beginning of the 180-day period falls during the validity of your residence permit. At that point, you stop looking at the days before it became valid, looking only at the days after it expired. On September 28th therefore, your count will be 89, and you will need to leave by September 29th.
Your dates are probably different, of course, so you may want to use the official Schengen Short-Stay calculator: http://ec.europa.eu/dgs/home-affairs/what-we-do/policies/borders-and-visas/border-crossing/schengen_calculator_en.html