It’s assigned proportionally but each state gets a few extra votes to give smaller states more weight.
Originally, states would then award these proportionally, but some state got “smart” and realized that if they gave all their votes to the most popular candidate they’d get more attention … other states soon followed suite and Madison went and died before he could fix this abuse of the system (which bothered him).