Preterite is used for completed actions in the past such as 'fui al baile anoche' 'I went to the dance last night'. This action is completed as you're not still at last night's dance. Furthermore, if you're referring to a specific, one-time event the preterite is used 'Hablé con mi madre de las dos hasta las tres' 'I spoke with my mother from 2 until 3'. The imperfect is used for actions in the past that are ongoing and may not have come to an end 'los chicos hablaban en español' 'The boys were speaking in Spanish'. We do not know whether the boys have finished speaking in Spanish or whether they still are so we use the imperfect.