This study aimed to establish associations between the environment and animal-based measures of welfare collected on 158 Finnish farms according to the Welfare Quality® systems for pigs. The data consisted of 95 welfare assessments in fattening pigs and 103 in sows, including suckling piglets. Principal Component Analysis had previously been applied to animal-based welfare measures (ABWM) and to the 20 descriptors of QBA to identify distinct types of welfare problems (WPT) and mood (MT), respectively. Generalised linear modeling was used to investigate environmental (space allowance, group size, feeding arrangement, floor type and use of enrichment or bedding) effects on WPT and MT scores. Those ABWMs not contributing to the major WPTs, but occurring on more than 40% of the farms, were considered important and used as outcome variables as well. The most important environmental determinants of pig welfare were space allowance for fattening pigs, group size in gestation and in the use of bedding for both fattening pigs and gestating sows. Bedding decreased tail biting and signs of fighting when used as a fairly thick layer for fattening pigs. In sows, the benefits of bedding, including less frustration and bursitis, required a smaller amount of material than in fattening pigs. An increasing space allowance was advantageous for fattening pigs, although signs of fighting increased in very spacious bedded pens. The positive effects of space, including a decrease of tail lesions and a more positive mood continued at least up to 1.5 m2 per fattening pig. Signs of resource shortage in sows increased with a growing group size according to a steepening curve.