Cannot just use an open collector driver with resistor pull-up because it would not survive a 24 volt short without foldback current limiting, or some other complexity.
Of course foldback current limiting would be better, but I believe there are situations when OC with pull-up can survive 24V short without foldback.
Typical OC I met use 4k7 to 5V pull-up. So about 1mA. If the same pull-up is on the other side transistor have to drive 2mA.
If you drive base with resistor divider giving about 1V and use 62 ohm in emitter you get about 5mA current source. Loaded with 2mA you have about 120mV drop at emitter resistor plus may be 100mV at saturated transistor so you output something like 0.25V what should be correctly recognized as 0 state.
Now shorted to 24V you have 24*5=120mW power dissipation in transistor. Assuming 50% signal fill you have 60mW average in transistor.
I am using such solution since 30 years but with intention to survive 12V short (or surge pulse limited to 25V by 18V transil). I have 33 ohm in emitter and use little higher than 1V base voltage but of course not for 500kbps signalling.
The problem I found was that a passive circuit with a high enough impedance to limit the current to a safe level was too high to allow 500 kHz operation. There are active circuits which could be used, but they would require too much space unless part of an integrated driver which I did not find.
There are active low impedance protection circuits which would allow very high speeds, but they also take too much space.
It depends on what the maximum acceptable current is?
A J-FET can be used to limit the current from the 24V supply.
I started with the lowest current limiting depletion mode FET of 1 to 3 milliamps and declared victory. The current can be lowered further with a resistance in series with the source, but this means taking more space for the resistor.
A current higher than 3 milliamps should be safe, but at some point a higher power FET is required, and schottky diodes have to be added to route the fault current into the positive supply of the microcontroller, which again takes more space.
I would prefer a different circuit, but given the space constraints, I would go with the depletion mode FET protection circuit. Depletion mode MOSFETs have an advantage here over JFETs because they are available with much higher power and voltage ratings, but either could work.