If A1 contains the start time and B1 contains the end time, then enter this formula in cell C1:
This tests to see if the end time appears to be less than the start time, if it is, it assumes that the times are before and after midnight.
It then adds 1 to the end time before subtracting it from the start time, because 1 is Excel's value for a whole day (24 hours).
If the end time is greater than the start time it just does a simple subtraction.
Note that Excel stores dates and times in the same number. Dates are the integer or whole number part of the number and the decimal part is the time.
0.5 is 12 noon, i.e., half-way through the day.
When you format cells as hh:mm, there is a possibility that date information is also present, but not visible, and this can give some unexpected results.
Add data validation to the start and end cells to ensure that only times are entered. Use a start time of 00:00 and an end time of 23:59