Both the preterite and imperfect tenses are used to describe an action that occurred in the past. Use of each will depend on the frequency of the action, whether it was completed or not, whether it was limited in time, and the context in which the action took place. Sometimes it may be possible to use either.
Use the preterite to express an action that was completed in the past:
Ayer vi a Julio y a Juan- yesterday I saw Julio and Juan.
Use of the imperfect here (veía) would suggest a continuous/ prolonged action, and would only really be used if it was describing the background against which another event (usually expressed in the preterite) took place:
Ayer veía la televisión cuando sonó el teléfono- yesterday I was watching television when the telephone rang.
The preterite is thus used to express instantaneous events, i.e. events that happened suddenly and in the moment:
Me rompí la pierna- I broke my leg; De repente oí el teléfono- suddenly I heard the phone.
It is also used to describe events that occurred within a specific time period, i.e. where the beginning and end of the period is clear. Look for time indicators such as 'durante' or 'por' to know if an action is limited in time:
Habló durante tres horas- he spoke for three hours; Por un instante pensé en mi hermana- for a moment I thought of my sister.
The imperfect is used to describe a past event that continued for an unspecified period of time- where the beginning and end is not clear:
Mi padre jugaba conmigo- my father played/ used to play with me (we don't know how long for).
It is therefore used to describe habitual actions and characteristics:
Cuando era pequeña iba al colegio en autobús- when I was young I used to go to school by bus.
Mi casa era grande; mi padre tenía los ojos azules- my house was big; my father had blue eyes.
The imperfect is used as the main tense in stories and when someone is evoking a memory/ past experience, as it is a descriptive tense:
Recuerdo que tenía que llevar un uniforme- I remember that I had to wear a uniform.
It often provides the background description to another event (see above):
Llovía cuando llegué- It was raining when I arrived.
When phrases like 'todos los días' or 'todos los años' are used, it may be possible to use either tense. If you see the action as complete, so if you are looking back on it as a whole, use the preterite:
Todos los días me levanté a las ocho- every day I got up at eight.
If you see it as happening at the time, use the imperfect:
Todos los días me levantaba a las ocho- every day I got up/ was getting up at eight.
Example of a short passage:
Trabajé como una camarera durante dos semanas (I worked as a waitress for two weeks. ‘Trabajar’ is used in the preterite because the action is limited in time). Tenía que llevar un uniforme y podía usar el teléfono del restaurante (I had to wear a uniform and I was able to use the restaurant telephone. ‘Tener’ and ‘poder’ are used in the imperfect because it is a description- they describe a state of affairs that was happening at the time). Todos los días hablé/ hablaba con los clientes (every day I talked/ was talking to the customers. ‘Hablar’ may be in the preterite or imperfect, since the phrase ‘todos los días’ has been used). Fue una experiencia maravillosa (it was a wonderful experience. ‘Ser’ is in the preterite because it describes an event that has finished/ been completed- the idea is that the person is looking back on the experience after it is over, and saying that it was wonderful from start to finish).