The Resistor Route
2. Why Resistors Are Usually a Bad Idea
Okay, I mentioned resistors earlier, and I practically shuddered. While technically possible to use a resistor to drop 24VDC to 5VDC, its generally a terrible idea, especially if your 5V device needs any significant amount of current. Resistors work by dissipating excess energy as heat. A lot of heat. Think of a toaster — that's essentially what you'd be creating, only on a smaller (but still potentially fire-hazard-y) scale.
The math is simple: Voltage = Current x Resistance (Ohm's Law). You can calculate the resistor value you'd need. However, the power dissipated by the resistor (Power = Voltage x Current) would be substantial. This means you'd need a high-wattage resistor, which is bulky, expensive, and still generates a considerable amount of heat. Plus, the output voltage would be highly dependent on the current draw of your 5V device. If the current changes, the voltage changes. Not ideal for stable operation.
Imagine trying to heat your entire house with a single candle. It's technically possible, but incredibly inefficient and ultimately impractical. Similarly, using a resistor to drop a significant voltage with a reasonable current draw is a recipe for wasted energy and potential component failure. There are much better ways to achieve the same goal without turning your project into a mini-space heater. You want to power your project, not accidentally cook it!
In summary, while resistors are simple and cheap, they are inefficient, generate excessive heat, and provide a poorly regulated output voltage in this scenario. Only consider using a resistor for very low current applications (think microamps), where the power dissipation is minimal. For anything else, explore the options below — your project (and your sanity) will thank you.