A magnetic field sensor based on the magnetic fluid injected into all the cladding air holes of the solid core photonic crystal fiber (PCF) is proposed. The 8.5 cm length of the PCF filled with magnetic fluid relates to single mode fiber to compose a Mach–Zehnder interferometer. The sensor relies on the tunable refractive index of the magnetic fluid and the characteristics of the PCF. A series of magnetic field strength is applied to this sensing structure. From the experimental results, the sensitivity of the magnetic field sensor is obtained as 7.055 × 10 − 4 dB / nT while a small change in wavelength shift is found. Due to a simple and easy fabrication technique, high sensitivity, and compactness, we are confident that the proposed sensor will find potential applications in measuring the magnetic field.