The definitions don't have any hard and fast rule and it really depends on the country and the time frame.
Historically you had muskets, and carbines. The carbine being a shortened musket for use with the cavalry or mounted infantry (dragoons). Later on we started to get 'rifles' which specifically referred to having rifling in the barrel of the firearm as opposed to the smooth bore which existed before then. Rifle-Muskets were in vogue for a few decades, still being muzzle loaders but having rifling before being replaced by dedicated breach loading rifles. The term Rifles usually meaning a infantry arm in this day and age, but pretty much every firearm issued today is rifled so it has somewhat lost its meaning.
Its at this point the definitions become less hard and fast. Some nations had cavalry firearms longer than others infantry arms. Some called them carbines, some called them short rifles, some called them rifles. Basically its what people decided to designate it/who was expected to use it as opposed to some hard and fast rule based on length.