The objective of this research is to explore compact celestial objects while considering the framework of an extended gravitational theory known as R+f(G) gravity. The notations R and G denote the Ricci scalar and the Gauss–Bonnet invariant, respectively. Radio pulsars, which are neutron stars with masses greater than 1.8 times that of the Sun (M⊙), provide exceptional opportunities for delving into fundamental physics in extraordinary environments unparalleled in the observable universe and surpassing the capabilities of experiments conducted on Earth. Through the utilization of both the linear and quadratic expressions of the function f(G)=α1G2, where α1 (with dimensional units of [length6]) are incorporated, we have achieved an accurate analytical solution for anisotropic perfect-fluid spheres in a state of hydrostatic equilibrium. By integrating the dimensional parameters α1 and the compactness factor, defined as C=2GMRc2, we showcase our capacity to encompass and depict all physical characteristics within the stellar structure. We illustrate that the model is capable of producing a stable arrangement for the pulsar PSR J0740+6620, encompassing its geometric and physical properties. We illustrate that by utilizing the quadratic form of G in the R+f(G) framework, the Krori-Barua ansatz establishes semi-analytical relationships between radial pressure (pr), tangential pressure (pt), and density (ρ). Remarkably, in the context of the positive/negative α1 quadratic R+f(G) gravity framework, the maximum compactness is inherently restricted to values fail below the Buchdahl limit when the surface density exceeds 4×1014 g/cm3. This differs from General Relativity (GR) in which the compactness is unlikely to approach the black hole limit. The model predicts a core density that is multiple times greater than the saturation nuclear density, represented as ρnuc=4×1014 g/cm3, and a surface density ρs that surpasses the nuclear saturation density. We offer the mass–radius diagram associated with the boundary density we have determined, and this diagram has been shown to be consistent with other observational discoveries.