First, find several vehicles that interest you online, and print out he kelly blue book values. Put them in a folder, along with the complete service records of the car you will be trading in. Then detail your trade in. Wash, wax, vacuum, armor-all, the works. Make that car look like something that you won't be afraid to drive away in if the dealer won't cave. (Chances are you might have to, so worst case scenario, now you have a very clean car!)
Do not, ever, go to a dealership and declare that you have a specific used car in mind (even though you absolutely should!) When they ask how much you are there to spend, be noncommittal. Look at cars randomly, allowing the salesperson to make their pitch, and only show interest in the car you want after the dealer tries to pitch it. In a negotiation, the person with the most information has the most power, so keep all the pertinent facts to yourself until absolutely necessary. That does not mean that you should be impolite or unfriendly. Just aloof, or at best distracted.
After you've shown interest, take a test drive with the dealer in the passenger seat. At this point, do your best impression of an impossible to please, entitled brat. Seriously. I want you to bitch about EVERY. SINGLE. THING that is not absolutely perfect with that car. Dings and dents? Loudly note them. Trans revs hard between third and fourth? Loudly note it. A/C is weak? Loudly note it. These things are your poker chips, and you're going to play them to great effect later on when you start arguing numbers.
After the drive, at which point there should be serious doubt in the dealer's mind if you're even going to buy it at all, you'll go inside and he'll give you two numbers. One for his car and one for yours.
Unless you buying a new car (FACEPUNCH!!!) both of the numbers he gives you will be complete horse shit. Be prepared with that KBB sheet that you printed off earlier. Point out, politely but firmly, what the fair value of the car would be if it was in good condition. Then point out that this particular car is a long way from good. You should then pivot, and point out that the value of your vehicle is significantly higher than the offer, both because fair value for good car is higher per KBB and because your meticulously maintained vehicle is significantly better maintained than an average "good" car.
At this point the dealer, if they are seasoned, will realize they are milking a stone and one of two things will happen: They will pretend to be in a huff, and disengage. This is because they are fairly certain they can sell the car for more later. Or, and this is the more likely result, they will say something like "what's it going to take here..." That is when you reveal that you want to be out the door for "$XXXX" and only if Y and Z service are added as a WE OWE on the vehicle. That $XXXX is a variable number. You should have a maximum you will not go over, determined before you even get there, but if the negotiation goes well you should push for more. You're likely to get it.