Upvote:2
Yes, you can leave the US if your student (F or J) visa has expired. The US does not prevent anyone from departing the country if they wish to do so.
However, you may need to get a new visa if you wish to return to the US.
You can re-enter the US without renewing your visa under automatic revalidation if your trip is to Canada, Mexico or certain Caribbean islands and you spend no more than 30 days outside the US. You must take a copy of your I-20 and I-94 with you.
For further information on automatic revalidation, see the CBP Automatic Revalidation Fact Sheet.
If you do not qualify for automatic revalidation, you will need to obtain a new visa in order to return to the US. Note that nationals of Iran, Syria and Sudan do not qualify for automatic revalidation in any case.