as long as the cpu and the motherboard have compatible socket and bios or bios update.
for example, you can use a sandy bridge core i3 2100 on a gigabyte z77 motherboard because core i3 supports lga 1155 socket (1155 pins). but if you need to put a core i5 3570k on a z68 motherboard, you will have to update the z68 motherboard's bios first despite z68 motherboard having same lga 1155 socket. another one - you cannot use an lga 775, core 2 duo cpu on an h61 motherboard because h61 motherboards' sockets cannot fit an lga 775 (775 pins) cpu.