How is a PCI / PCIe BAR size determined?

I know that the base address register (BAR) in PCI configuration space defines the start location of a PCI address, but how does the size of this region get established? Surely this is a property ...