Use had to + a verb for something you needed to do in the past.
had to + a verb
I had to walk home last night.
She had to take the bus.
Try it: Woman: Why weren't you at the party last night? Man: I ___ study for a test. Choose what the man says. (had to / didn't have to / has to) Answer: had to — He missed the party last night for a test, so he had to study.
didn't have to + a verb
Use didn't have to + a verb when there was no rule, so you could choose.
I didn't have to go to school today.
Try it: Man: Was the form long? Woman: No. I ___ write much. Just my name and address. Choose what the woman says. (didn't have to / had to / don't have to) Answer: didn't have to — The form needed only her name and address, so she didn't have to write much.
Did you have to …?
To ask about a rule in the past, say Did you have to + a verb?
Did you have to wear a uniform at school?
Did he have to pay for the ticket?
Try it: Man: ___ get up early for the trip? Woman: Yes. The train left at six, so I got up at five. Choose what the man says. (Did you have to / Do you have to / Did you forget to) Answer: Did you have to — The trip is over and the train time made her get up at five, so he asks Did you have to.