The resource potential of the Upper Triassic Yanchang Formation in the Ordos Basin is considerably large. However, owing to the low porosity and permeability, poor connectivity, and strong heterogeneity of tight sandstone, predicting the porosity of tight sandstone in this formation poses substantial challenges. The lithology of Chang 71 sub-member is dominated by arkose and lithic arkose, wherein the porosities mainly ranged between 3 and 13% and pore types were mainly feldspar dissolution pores. Based on core sample experiments and thin section analysis, combined with conventional logging curves, we proposed a three-porosity weighted average prediction method under lithological control, and a novel method for reading logging curves controlled by logging resolution is developed. We used principal component analysis to optimise the logging curves and reduce the impact of complex coupling relationships between logging curves on lithofacies identification. The stacking algorithm, which is a combination of the random forest and extreme gradient boosting models, was applied to divide the lithofacies into five categories: homogeneous-distributary-channel fine sandstone, heterogeneous-distributary-channel fine sandstone, homogeneous-mouth-bar fine sandstone, heterogeneous-mouth-bar fine sandstone, and shallow lacustrine mudstone. Compared with the results of manual classification based on logs, the accuracy of lithofacies recognition was approximately 94.2%. Additionally, sensitivity analysis of porosity curves was conducted on four types of lithofacies (i.e., except for shallow lacustrine mudstone), and porosity models for each lithofacies were established, providing an effective and objective method for the accurate prediction of porosity. This prediction method comprehensively considers sedimentary factors and incorporates statistics that are fitted using multiple linear regression, which is highly reliable. In the Chang 71 sub-member, the fitting degree between the predicted and core porosities reached 0.912, indicating that this three-porosity weighted average method based on lithofacies constraints is reasonable, reliable, and has stronger adaptability than the those reported previously. The prediction method based on lithofacies control and weight analysis can be applied to other tight sandstones, providing reliable technical support for oil and gas exploration and development.