Plan around first and last trains.
Catching the last train is a backwards calculation from its departure. Subtract the walk or transfer to the station and a platform buffer, and you have the latest moment you can leave where you are; the difference between that and when you can actually leave is your slack. Twenty minutes of slack is comfortable, under ten is a gamble, and negative means planning the taxi now rather than discovering it at 00:35. Two things routinely destroy the margin: last trains often depart from a different platform or even a different station than the daytime service, and the last connection is frequently earlier than the last train on the main line — check both legs, not just the final one.
First and Last Train Planner
Lead time = walk minutes + platform buffer; latest leave = last train departure - lead time / 60; slack minutes = (latest leave - when you can leave) x 60
Because branch and feeder services usually finish before the trunk route. The last train from the city may run at 00:30 but the last bus or branch line from your arrival station could be at 23:45.
At least five minutes on the platform and more at a large terminus, where finding the right platform can take that long. For the last service of the night, ten is safer — there is no next one.