The 30-day window is when you are expected to apply, and the expiry date is the hard deadline. The law frames the requirement as applying within 30 days before expiry; applying earlier than that is generally not what the rule contemplates, and the expiry date itself is the point after which you are overstaying.
Nationwide (all cities)
The window and the deadline
The 30-day figure is the window in which you are required to apply, and the expiry date is the deadline you cannot pass.
What the law says
The Exit and Entry Administration Law sets the rule. A foreigner whose residence permit needs to be extended must apply within 30 days before it expires. This is a requirement tied to the period immediately before expiry, not an open-ended permission to apply far in advance.
The practical reading
The practical reading is that the 30-day window is the time to act, and the expiry date is the hard line. Applying much earlier than 30 days is not what the rule contemplates — the application is for extending a permit that is about to lapse, and the authorities work against the upcoming expiry. The key is not to leave it until after the expiry date, because once it passes you are overstaying.
The takeaway
So treat the 30-day window as when you should apply, and the expiry date as the deadline you must not cross.