In general:
Promotions: When he is commissioned as an ensign or second lieutenant (paygrade O-1) on Comm Day, he is assigned a unique lineal number and his date of rank is that day. Lineal number is where he ranks in seniority compared to all other officers in his service. OCS, ROTC, direct commission programs, same. The date of rank (he will have subsequent ones) and lineal number (never changes) are the markers for all subsequent promotions. First two promotions are fog-a-mirror: with sufficient time in grade, acceptable performance and reporting senior's recommendation for promotion to next rank. O-4 (lieutenant commander, major) promotion is a competitive board selection.
Retirement: USNA time does not count for military retirement. It can be factored into Federal/civil service retirement. Example: USNA grad leaves AD, goes to work for HLS as a civilian program analyst, can count USNA years toward Fed retirement. Very rough description.
Most officers have no clue about their lineal number until they are more senior. Some fun stories...Navy ships often tie up to the pier in a nest, with ships tied to each other. Unless operational needs dictate, the senior CO gets the preferred inboard berth, the pierside one. How determined? Lowest lineal number. You could have 3 USNA classmates, all destroyer skippers, all same rank, and their lineal numbers will determine seniority. Goes back to class order of merit. Or you could have an OCS skipper, commissioned January that same year, have the inboard berth.