In general, it takes eight years of ownership of a German residence permit to be eligible to apply for the German citizenship.
This period can be shortened in some situations; for example it is reduced to seven years, if the applicant has successfully participated to an integration course. It can be reduced to six years, if the applicant can additionally prove that he made special efforts in integration to Germany, especially if he can prove that his German language skills are better than “sufficient” which generally is German level B-1.
It is generally harmless if the applicant stayed outside of Germany for several weeks or months in a row. However, stays for more than six months in a row can be harmful. The German immigration authorities generally deem that Germany is not your usual residence anymore when staying outside of Germany for more than six months in a row. Therefore, those stays generally are not counted anymore when applying for a German citizenship. Moreover, you might lose your German residence permit by law, even if your German residence permit did not expired, yet, or even if you own an unlimited German residence permit. Therefore, stays for more than six months in a row should be avoided in general or it should be communicated to the authorities in advance to clarify if any negative consequences might arise.
You wish to get information about German Citizenship Law?