A private key - basically - is just a random 256 bit number.
But what you import into electrum is most likely the private key in the WIF (= Wallet Import Format).
And the WIF key contains a checksum. So each wallet can easily check whether it is a valid private key or not by looking at the checksum (last 4 byte).
You can read more about the wallet import format
here.