Basically will message number one stay number one under another IMAP session/location?
The UID will stay the same forever, so long as the UIDVALIDITY doesn't change (it's very rare for UIDVALIDITY to change)
The MSGNO (sequence from 1 to "EXISTS") is local to this specific connection. If you client opens multiple connections, the MSGNO can actually be different in each one.
That said, MSGNO and UID are always both sorted the same way. A higher MSGNO will always map to a higher UID.
Some IMAP commands can cause MSGNO to change - but you will always see an EXPUNGE result telling you which one got removed - all higher numbers decrease by 1 at that point. If new messages get added, you'll get an updated EXISTS as well to tell you how many.
(all this changes if you "ENABLE QRESYNC" and the server supports it - but that's the rules of basic IMAP).
As Janne pointed out in the comments - RFC3501 contains all the gory details about which commands are allowed to change MSGNO, and which have to preserve it, even if some MSGNOs now point to expunged messages.
In short - if you're interacting across different sessions or different connections within the same session, use the UID variants of the commands and you'll be safe.