When you end your tenancy and leave an apartment, you must return the keys to the landlord. It's generally best to return the keys to the landlord or management office personally, and get a written receipt documenting their delivery. Another option is to give them back to an authorized agent in the presence of a witness you bring along with you. It's better to give the keys directly to the landlord if possible, rather than the building's super or someone of lesser authority. In disputes between landlords and tenants, supers often side with the landlord, and might do so even when there's hard evidence of the keys changing hands. Personal delivery is preferable to mailing them back, even by certified mail. You want the strongest possible evidence that you delivered the keys on the date they were handed over. Legal proof of having returned the keys helps to protect you from the landlord later claiming the apartment was not actually vacated on the date you left. If the landlord can claim your occupancy continued into the following month, he or she may attempt to keep the security deposit, deem the lease as renewed when it wasn't, or make you pay additional rent for supposed extra time in residence.
Attention New York City Tenants: Get more more information on Landlord Tenant matters at the McAdams Law main site here.