The first two or three numbers/letters are assigned by either ICAO or IATA. Can’t quite recall which but believe it was IATA. The rest of the flight number can be assigned as the airline sees fit using any numbers or letters (Yes, letters can be used as well, but rarely are!). Most airlines go for 3 or 4 numbers for their flight numbers.