Generally, F-1 visas are marked with a "Duration of Status" seal. This means you are legally allowed to remain in the United States as long as you are a full-time student, even if your passport's visa expires while you are still in the U.S.
Upon completion of your studies, F-1 visa holders have 60 days to transfer to another school or leave the United States.
Your F-1 visa allows you to travel in the United States and to leave and return, unless your visa has expired. As long as you continue to study, you may stay in the U.S. on an expired student visa; but if you leave the country on the expired student visa, you will have to acquire a new F-1 visa before returning to resume your studies.
If you take more than five months off school, you will need to apply for a new F-1 visa to continue your studies.