Getting a deposit back cleanly is mostly about process discipline in the final weeks. Start with notice: reread your contract for the required notice period and form, and send it in writing with proof of delivery, since verbal notice is the root of many lost deposits. If leaving early, check whether you have a break clause, whether local law grants an exit right with notice, or whether you owe rent until a replacement is found; proposing a replacement tenant yourself often softens the cost, and negotiating a documented settlement beats simply leaving.
Then prepare the property. Settle final utility bills and record closing meter readings with photos. Clean thoroughly, or hire an end-of-tenancy clean where that's customary, and fix trivial damage like wall holes yourself, since landlords bill generously for small repairs.
Do the final inspection jointly, walk through with the landlord, agree condition on the spot, and get a signed handover document recording the state, the readings, and the keys returned.