The USCIS must receive your application no later than the day you terminate your H-1B employment.
If you are no longer in H-1B status or your H-1B status will end more than 30 days before the program start date on your I-20, you cannot apply for a change of status inside the U.S. Instead, you will have to change your status by traveling outside the U.S., applying for an F-1 visa and entering the U.S. as an F-1 student.