I ran these numbers for a number of brands and models (over a decade ago, so the data's stale, but reliability has largely improved since then, while gas mileage has largely stagnated except in trucks), and it's not as bad as you'd think. Some highlights:

1. Incremental costs like tires/oil/gas/insurance matter a lot more than the purchase price and repairs. That has some knock-on impacts:

a. Most people on HN can easily afford to not carry full coverage if they drive something like a 2012 Civic. If the thing is totalled and not covered by the other party, just buy another. If you purchase with a loan or buy a more expensive car then even a lot of developers in their first few years (the majority of developers IIRC) can't afford that luxury and have to purchase full coverage -- paying for the same risk they'd assume by not having full coverage, plus the insurance company's profits.

b. The first 5-10 years of a car's life are expensive not just because of depreciation, insurance, and financial instruments but also because of a lack of cheap replacement parts and requirements for things like specific kinds of oil without good third-party substitutes.

c. Gas mileage (or equivalent electric costs, based on how you'll actually charge the thing in real life) was the driving factor behind the sweet spot being closer to 8-14 year old cars rather than even older cars (you don't have much significant amortized repair cost till at least a 20yr old car).

d. You can save almost as much money adopting relaxed, safe driving habits as you can optimizing the purchase year. Instead of hitting the gas right up until the car in front of you at a red light and then hitting your brakes, try coasting in. If there's nobody at the light and you'll definitely have to stop before it turns, slow down early and coast toward it rather than slowing down at the end (so that you can maintain 10-20mph of kinetic energy as the light turns green rather than coming to a complete stop). If you're driving somewhere with a lot of stop signs, it's probably residential and shouldn't be driven in quickly anyway, but lower your top speed to the actual speed limit (25 vs 30mph with frequent stops saves 30% on your incremental gas mileage).

2. The first few years of ownership are much more expensive than even years 18, 19, 20. Depreciation hits like a truck.

3. If you lease or take out anything like a 3yr+ loan, the extra cost of that financial instrument more than makes up for the extra repairs even out to a 30yr old car.

4. The sweet-spot in cost-per-year (keeping in mind that with transaction costs you can't save money switching to an optimally aged car every year) was in the 8-14yr range, depending on a lot of factors. Since gas mileage has not significantly improved since I ran these numbers, and since cars are more reliable, I expect the cheapest cars to own to be much older than that (probably 15-20yrs, but that's just a hunch). Electric cars throw a potential wrench in things, but whether those are actually cheaper is a lot more sensitive to your personal situation than with gas cars, so I won't touch on it.

5. Repairs on old cars are much more expensive when you put them off. Hear a knocking as you turn while driving? Have the mechanic replace a bushing or whatever. Haven't replaced anything for 2yrs? Have the mechanic inspect all your various bushings/housings/... during your normal oil change (mechanics tend to be cheaper and better than all those quick-oil-change places by the way). Getting towed to a mechanic and having to rent a car, skip work, uber, or mooch off a friend is expensive. Addressing problems proactively is cheaper than newish-car depreciation out to at least 30yrs -- even counting a (stochastic) engine or transmission replacement somewhere in that interval.

Cost of ownership depends on a lot of factors. The broad trends are largely correct, but the exact inflection point depends on your insurance's perception of your risk level, whether you drive significantly more/less than the average person, .... If you drive fewer miles each year, older cars are even more attractive.