English hides a distinction Spanish makes you choose
"I walked to school" is a single English sentence that could describe a one-time trip or a five-year daily routine — English doesn't force you to specify which. Spanish does: caminé a la escuela (preterite) says it happened, as a completed event; caminaba a la escuela (imperfect) says it was an ongoing or repeated action, described from the inside, with no stated beginning or end. Neither is more "past" than the other, and neither is inherently longer or shorter — the difference is entirely about how the speaker is framing the action, not when or how long it took.
This is the single hardest thing about the pair for English speakers, because English simply doesn't require you to make this choice, so there's no equivalent instinct to draw on. Spanish grammar treats it as a question of aspect — whether an action is viewed as a finished whole or as unfolding — not a question of tense in the sense of "how long ago."
Preterite: a completed action with an edge
The preterite reports an action as done, viewed from outside as a single, bounded event, whether that event took an instant or a decade. El mayordomo bajó las escaleras ("The butler went down the stairs") reports that the descent was completed. Vivió en México durante diez años ("She lived in Mexico for ten years") is also preterite, even though ten years is a long stretch — because the sentence is framing that decade as a closed, completed chapter, not describing what daily life was like while it was happening.
Preterite is the tense that moves a story's plot forward: it answers "then what happened?" A string of preterite verbs in a row reads as a sequence of completed events, one after another.
Imperfect: an action viewed from the inside, without its edges
The imperfect presents a past situation from inside its own duration, without committing to when it started or ended. El mayordomo bajaba las escaleras ("The butler was going down the stairs") describes the descent in progress — it doesn't say whether he reached the bottom. Compare it to the preterite version above: same verb, same subject, but the imperfect leaves the ending open.
Imperfect is the tense for background, description, and habitual or repeated actions in the past: Cuando era niño, jugaba en el parque todos los días ("When I was a kid, I used to play in the park every day") — a repeated routine with no single completed instance being reported. It's also the tense for setting a scene: Llovía y hacía frío ("It was raining and it was cold") describes the conditions surrounding an event, not the event itself.
Why the same sentence can use either, on purpose
The clearest way to see the distinction is a pair that uses the same verb and changes only the aspect. Cuando llegué, ella dormía ("When I arrived, she was sleeping") uses preterite for the arrival — a completed, single event — and imperfect for the sleeping, which was already in progress and had no marked start or end from the sentence's point of view. Swap the verbs: Cuando llegaba, ella durmió would be an odd sentence, because it treats the arrival as ongoing and the sleeping as a sudden, completed event, which doesn't match how these situations normally unfold.
A narrative typically braids both together: imperfect sets the scene and describes ongoing conditions, preterite reports the events that interrupt or move through that scene. This is also why "how long ago" or "how long it lasted" is the wrong test — vivió allí diez años (preterite, a completed ten-year stretch) and vivía allí cuando pasó el terremoto (imperfect, an ongoing state interrupted by a preterite event) both involve "living somewhere" and can both refer to long periods; what differs is whether that period is being treated as a finished block or as an ongoing backdrop.
One irregular verb worth knowing both forms of by heart is ser — its preterite (fui, fue...) and imperfect (era, eras...) are both common and completely different-looking from each other, which makes it a good verb to drill this distinction on. See the full ser conjugation table for every form.