Overall cell selection mechanism can be summerized as follows.
i) When you power on UE (e.g, a mobile phone) or turn off Airplane mode.
ii) UE scans energy level (cell power) from all the cells around it.
iii) If it detects the power which is greater than a certain level (this level is specified in UE radio stack software and this value would vary depending on UE manufacturer and model), it decodes MIB(Master Information Block) and a certain SIB(System Information Block) that carries Cell Selection parameters. Which SIB carries that kind of information is different with each radio technology. See the page linked below if you are interested in more details on these SIBs for any specific radio technology.
iv) After decoding MIB/SIBs and getting Cell Selection parameters, it estimates the cell selection criteria calculated from the cell selection parameter and the algorithm defined by the industry standards (e.g, 3GPP). See the page linked below if you are interested in more details on how UE estimates the criteria.
v) Based on the estimation in previous step, choose the best fitting cell and perform registration process.
As mentioned above, overall cell selection mechanism is same in 3G/4G/5G, but the detailed parameters and mechanism varies a little bit depending on Radio Technology. See following pages if you are interested in further details.