From the Codex;
in ascending order of responsibility, the ranks of the Alliance are:
ENLISTED
Serviceman 3rd Class/Private 2nd Class
Serviceman 2nd Class/Private 1st Class
Serviceman 1st Class/Corporal
NCOs
Service Chief
Gunnery Chief
Operations Chief
OFFICERS
2nd Lieutenant
1st Lieutenant
Staff Lieutenant
Lieutenant Commander
Staff Commander
Captain/Major
Rear Admiral/General
Admiral
Fleet Admiral
Its not perfect. I think there's a lot of military-experienced gamers questioning this but Alliance isn't US military and its a military fiction written by a Star Wars writer and isn't intended to be accurate.
----
(Btw, Dr Chakwas is a Major too.)
In ME1, under Captain Anderson, Lieutenant Commander Shepard is the XO of SSV Normandy. Since nobody refer Shepard as a Lieutenant Commander, so I just assume Shepard was just recently promoted as a Staff Commander once s/he became an XO. But soon after, Shepard gain a Spectre status and effectively remove Shepard from the Alliance military command and place him/her as an agent to the Citadel Council and in a position to be neutral (so you can be either Pro-Humanity or Pro-Alien). If Anderson had step down and given Normandy to Shepard before the Council promotion, Shepard could have become a Captain instead.
Kaidan was a Staff Lieutenant in ME1 and is a Staff Commander (same rank as Shepard) in ME2 and later was given the command of the Special Operations Biotics Division. Why wouldn't he be promoted and a rank higher than Shepard by ME3? He is an experienced military officer who have long history and commendations as a special operative even before being assigned to the Normandy. By ME2, you found him on Horizon and he was working for the council, which meant he is a Spectre candidate who was investigating a possible rogue Spectre in the Terminus system. Sounds familiar? He would have become a Spectre like Shepard in ME1 if he didn't get the evidence that the Collectors was involved in the disappearance and it wasn't Shepard and Cerberus that kidnapped them.
However, as a Spectre, since he isn't within Alliance military anymore, he is an equal to Shepard even if he is higher rank in the military. He choose to be assigned to the Normandy which is under Shepard's command. But unlike everyone else, Kaidan didn't assume any ship duties but he's more like Miranda in ME2, busy with paperwork for the Alliance and the council and commanding his Spec Ops from a distance.
Also, Shepard was reinstated into Alliance systems and given the command of part of Alliance fleets and was assigned to gather resources for the Crucible Project, foreign diplomatic efforts, colonial evacuations and the operation to retake Earth. Essentially, ME3's Shepard outrank everyone except for Hackett and Anderson.
What was more nonsensical was Ashley's jump from being Operations Chief to Lieutenant Commander in six months of "officer's training". The only way I could reason this was the military promoted her (excessively) as an apology to her father and grandfather. However, her inexperience really show especially with Udina.