Getting out of a lease agreement can be tricky, but if you feel like you have no other choice, start by reading your lease very carefully. Ideally, you should have read through your lease before signing it in the first place, so you should be at least roughly familiar with the section of the lease which details giving notice and moving out. In the worst case scenario, you may be responsible for your rent through the end of the lease whether or not you live in your house; however, you may be able to get out of a lease agreement without paying through the nose, especially if you do it carefully. If you are trying to get out of a lease, you should definitely contact a local tenant's rights organization or a lawyer to help you out, as these professionals are familiar with all of the ways to legally get out of a lease agreement.
Start by determining why you want to leave. If you are leaving because of poor conditions in your apartment, document those conditions carefully and start complaining, if you haven't already. You may be able to break your lease because your landlord has already broken it by failing to provide safe and sanitary conditions. If you are leaving because of roommate issues, you may be able to get a roommate release which removes you from the lease while leaving your roommates responsible. If you are relocating for school, a job, or something else, it can be harder to get out of a lease agreement, although if your job offers relocation assistance, ask for help with getting out of your current lease.
Lease terms vary widely. If you have a month to month lease, typically you need to give notice a month in advance and then you can move out. If you have a yearly or semi-annual lease, you may still be able to give notice and leave before the term of the lease is up; information about this can be found in your lease. Annual leases may ask for two months notice if you intend to leave, which gives your landlord ample time to find new tenants. Some annual leases are also flexible enough to allow subletters, in which case you don't need to get out of a lease agreement, you just need to find a trustworthy tenant to sublet to.
If you have a friendly, flexible landlord, you may want to approach him or her about the problem. Landlords prefer not to see their leases broken, but they would rather have ample warning than lose a month's rent because you vanished in the night. If you have a good reason and you offer to help find a new tenant, a landlord may let you get out of a lease agreement early with minimal penalties. If you know that your landlord is not very friendly or helpful, hire a lawyer to look over your lease; the expense could end up saving you money in the long term if the lawyer finds a loophole.
Try to avoid feeling trapped by your lease agreement, and don't let panic dictate your actions. There are all sorts of reasons to need to move early, and while you are legally responsible for your lease, all landlords are aware that unforeseen circumstances do arrive. By asking for help from a tenant's rights advocate and approaching the problem from every possible angle, you should be able to get out of a lease agreement with minimal pain, financial or otherwise.