The very broad general rule is 1st author did much of the work operationally, the oversight of the project, and even the writing of the paper. This is usually the person that takes a project from start to finish. Someone senior usually tells them "It would be great to do a project on blah blah blah. Why don't you go and tackle it" to which they actually get it done. They certainly may get some help in the form of research assistants/associates, etc, but they "own" the project and take a lead on it. First authorship is considered a significant achievement, generally.
The last author, also called the senior author, is PI or head of the research group (formal or informal Primary Investigator, head of the lab, Chief of a medical unit, or Director of a certain program, etc). This is the "someone senior" typically from above who has mentored or supervised the project. Their credibility and reputation as a senior author is also factored into each paper they write as last (senior) author.
People in the middle are generally listed in order of contribution from most to least - but this convention is often broken. Also, in clinical medicine, there are definitely a lot of people who only glance at the people in-between (eg. the difference between 2nd and 9th in a 10 author paper is negligible). This rule is broken - in my mind - for more junior scientists (undergrads, pre-meds, research assistants looking to get into med school) because quite frankly getting to contribute to any study in any capacity is a differentiator to those that have no publications of any kind.
If there are two equal collaborators, it's ultimately a flip of a coin. If you are a researcher in someone's lab and only two of you are on a paper, it's almost always: researcher, head of lab. If person A did proportionally more intellectual work than person b, then generally person A goes first, person b second.
This is all convention. Generally, your mentor/preceptor should be able to help guide you as far as author order and giving credit where credit is due.