Saph is correct, but I'll expand.
Each regiment had a fix establishment of officers, but is allowed to have one extra 2Lt as a brevet 2Lt per coy. Typical entry into service on passing out from USMA was as a brevet 2Lt, and the higher the ranking in the class, the more prestigious a regiment/corps you were assigned to. In each year, there would be a set number each corps could take. The Engineers were considered the highest, then the Topographic Engineers, then Ordnance, then Dragoons, then Artillery, then Infantry and Rifles.
Typically, each regiment was full, and an officer could expect to spend the first few years in service as a Bvt 2Lt, that is Commissioned as a 2Lt in the Army (with seniority defined by their position in the USMA class), but as a supernumenary attached to a regiment awaiting lineal "promotion" to 2Lt. The rank, like all brevets, was a real Commission requiring the approval of Congress.
Generally, all promotion was strictly lineal by seniority. The officer would wait to move up to 2Lt, then 1Lt and then Capt in their regiment. For field ranks, lineal promotion is by corps; for example all infantry regiments were considered a single corps so when a majority became available it would go to the senior captain across the infantry regiments. Frocking to general officer was by selection.
Brevets were awarded for ten years continuous service without promotion, for named actions, or to preserve rank when units were reduced. At times, brevets gave seniority for regimental promotion, and at times this was ignored.
Taking R.E. Lee as an example:
Lee ranked second in the class of 1829, and the Engineers were accepting 2 bvt 2Lts that year. Thus he is assigned as a bvt 2Lt to the Corps of Engineers. On the 1830 Army Register he ranks as the 3rd bvt 2Lt - he has to move up three slots to become a regimental 2Lt.
By 1832 Lee had risen six places. All lineal Commissions were confirmed by Congress in March. Lee is new a 2Lt in the Engineers with seniority to 1st July 1829. This is another point that changed - in the 1830's when promoted to a rank in the regiment equal to rank in the army (brevet rank) then the regimental seniority backdated immediately the the brevet. By the ACW this was not being done, and both ranks were left on the Register.
In 1836 Lee had risen to be the senior 2Lt and another move up happens, making him an acting 1Lt until March 1837, where the rank is confirmed by Congress as 1Lt.
In 1838 the establishment of the Engineers is increased from the equivalent of six coys (6 each allowed of Capt, 1Lt, 2Lt and bvt 2Lt) to ten. All subalterns moved up seven slots (the establishment was increased by 1 Lt Col, 2 Majs and 4 Capts), and Lee lineally ascends to Capt.
Now, if Lee had not received a promotion or brevet before 1848, he would be due to be bumped to brevet major in March 1849. However, he was awarded three brevets for Mexico in August 1848, all of which were backdated to the event. Lee is still a regimental captain, but is a bird colonel in the Army with seniority to 13th September 1847.
In 1852, Lee was assigned to be superintendent of the USMA in the rank of colonel, according to his Army rank. He is still a captain in the Engineers. In 1855, when the Corps of Cavalry was created, Lee had risen to be the 2nd Capt in the Engineers, but was assigned to the Cavalry. As a new corps, no-one had any regimental rank, and so Army rank applied. Lee was technically second in seniority of the assigned officers (EV Sumner, RE Lee then JE Johnston), but AS Johnston, holding seniority in the line of an ex-2Lt (6th Inf), the now defunct rank of Colonel of Texas Volunteers and the staff rank of Paymaster, was dropped in ahead of Lee. It was a political appointment as the State of Texas liked him.
Finally, in March 1861 Col Sumner is promoted BG vice Twiggs, dismissed. Bvt Col RE Lee of the 2nd Cavalry lineally ascended to by Col of the 1st Cavalry and resigned soonafter.