Magento gets state name, ID, code from region ID or region code.

Get state code from state id

1
2
$region = Mage::getModel('directory/region')->load(12);
$state_code = $region->getCode(); //CA

Get state name from state id

1
2
$region = Mage::getModel('directory/region')->load(12);
$state_name = $region->getName(); //California

Get state id from state code

1
2
$region = Mage::getModel('directory/region')->loadByCode('CA', 'US');
$state_id = $region->getId(); //12