Terminating a contract can be tricky process with lots of rules surrounding it. Once you rent an apartment, the agreement can only be terminated by the tenant (except under special circumstances). This means, for example, that the landlord cannot simply cancel your contract if he/she dislikes you. Visit this website to see the cases where a landlord may terminate a contract.
If you want to terminate your contract as a tenant, you can do this through a signed letter to the landlord, stating that you want to end the rental agreement.
You still have to deal with a notice when cancelling your rent. Normally, the notice equals the term of payment, which has been written down in the contract. For example, if you pay rent monthly, you have to give one month’s notice. Unless differently stated in the rental agreement, the cancellation of the rent needs to be done before the first day of the month.