Logo: A rental agreement and two keys on a house shaped key ring (Epoxydude, fStop, Getty Images)
When I was an apartment building manager, one of my least favorite duties was doing the "walk-through" when someone moved out. Every bit of damage and every still-dirty spot in the place meant more money taken from the departing tenant's security deposit.

As you might imagine, some of those people took that very personally. One tenant argued that red candle wax on the rug was just "normal wear." Another argued that the carpets -- new when he moved in -- "would have had to be replaced anyway," because he'd lived there for almost a year and a half.

Another renter swore he'd washed the kitchen linoleum, upon which swirls of dirt were clearly visible. He later admitted that his "cleaning" method was to wipe the floor with an old soccer jersey soaked in water.

A tenant became furious when I told him he'd have to pay for the hole punched in the bedroom door. He claimed it was that way from the beginning, but could not explain why he'd initialed and signed the move-in sheet that reported "no visible damage" in the bedroom walls and doors.

Maybe these are the kinds of people who answered a recent Rent.com survey, which found that 26% of renters had lost a security deposit.

But that 26% figure wasn’t the worst part.

The worst part is this: Of those who didn't get their deposits back, more than one-third (36%) said the landlord didn't say why.

Failing to give an explanation is illegal in some states. To learn the rules where you live, see Nolo.com's state-by-state list of security deposit laws.

It's not clear whether how many of those renters who got stiffed tried to fight and lost versus merely shrugging and accepting. Read on for more tips to keep this from happening to you.

Four basic precautions

Read your lease.
On several occasions I had to tell tenants they'd missed the window (which was clearly stated in the lease) for giving written notice to vacate. That meant they owed the next month's rent even if they wouldn't be living there. (If the apartment got rented within that month, however, the landlord would return a portion of the deposit.)

Take two sets of pictures.
One when you move in and one when you're ready to move out. That is, unless you want to risk being charged for imaginary damage.

Deal with pet problems. Take action immediately if your cat or dog does something damp and disgusting on the rug. Sometimes a good carpet cleaner/spot remover can take care of these problems -- if they're still fresh. And yes, the landlord will notice that mustard-colored hairball stain.

Know what "clean" means. The building I managed had an exhaustive list of what kind of cleaning was expected upon move-out. If it isn't specified in either your lease or on a separate sheet, ask your landlord to give you one in writing. Then follow it, for heaven's sake. (Hint: A damp shirt isn't enough to clean the floor properly.)

In the building I managed, a move-in/move-out form had to be checked off room by room and feature by feature. A copy was then given to the tenant, which meant that he or she could prove the place was certified to be clean and undamaged upon vacating.

Not every landlord has scruples, of course (see that "36%" figure above). If you think there could be trouble, make sure you're there when the building manager or landlord walks through your place for the last time.

In fact, consider shooting another set of "after" photos during the walk-through. That way it will be clear that you know your rights.

Stand up for yourself

And if only part of your deposit is returned, with some trumped-up reason (or no reason) as to why? Don't cash that check! It might be construed as accepting the landlord's decision.

According to Nolo.com's "Get your security deposit back," you should first try to work something out. Put any agreement in writing (e.g., "tenant will return on Feb. 10, 2013, to clean oven and refrigerator") that's signed by both parties. If the landlord reneges, this document will be useful in small claims court.

If nothing can be negotiated, then send a "demand letter," i.e., a written request for the return of the deposit. In many states you must do this in writing before being able to go to small claims court.

Even if you don't have to do this, a letter puts the landlord on notice that you're not going to drop this. The Nolo article explains what to include in the letter, such as a citation of state security deposit law and copies of your move-out documents.

Document your digs, read your lease, know your rights -- and be prepared to follow through.

More on MSN Money: