The usual way to accomplish this is with a comparator. I use the classic LM393 here:

simulate this circuit – Schematic created using CircuitLab
It compares two potentials, \$V_P\$ and \$V_Q\$, outputting high (+5V here, since that's the supply I've used) when \$V_P>V_Q\$, and low (0V) otherwise.
Potential \$V_P\$ is a fraction of the input \$V_{IN}\$:
$$ V_P = V_{IN}\frac{R_2}{R_1+R_2} $$
Potential \$V_Q\$ is a fraction of the supply:
$$ V_Q = 5 \times \frac{R_4}{R_3+R_4} $$
I have arranged things such that when \$V_{IN}=+5.1\rm V\$, then \$V_P = V_Q = 0.65\rm V\$. I have also included about 0.1V of hysteresis, using positive feedback via R6, to prevent oscillations at the threshold. It means that for \$V_{OUT}\$ to go high, \$V_{IN}\$ must exceed +5.1V, but to return low again it must fall under +5V.
It's important to respect the acceptable input voltage range of the comparator (see the datasheet), so R1 and R2 are chosen to ensure that even a 24V input will not cause P to exceed that.
Here's a simulation showing \$V_{IN}\$ (blue) rising and falling slowly, and the resulting \$V_{OUT}\$ (orange):

1is not synonymous withhigh\$\endgroup\$