There are options available for when your program ends you can look at SEVIS #10 to see what they are.
There is also discussion on the subject at the SEVIS F1 transfers page:
If USCIS denies the reinstatement application , the student must leave the United States immediately or risk being placed in removal proceedings at any time under §237(a)(C)(i) of the Immigration and Nationality Act (INA), as amended.
There are always other options that you can exploit with respect to changing your status but you can if not you have 60 day grace period from the time of the program's end to the time you have to leave the country:
1.14. May an F-1 student work on campus during the 60-day grace period after the program end date?
No. The 60-day "grace" period after graduation or post-completion OPT is for an F-1 student to prepare to leave the United States, unless the student is beginning a new program of study. An F-1 student may consider applying for post-completion OPT to continue working after graduation.