Polyaniline–NiFe2O4 nanocomposites (PANI–NiFe2O4) with different contents of NiFe2O4 (2.5, 5 and 50wt%) were prepared via in situ chemical oxidation polymerization, while the nanoparticles nickel ferrite were synthesized by sol–gel method. The prepared samples were characterized using some techniques such as Fourier transforms infrared (FTIR), X-ray diffraction (XRD), scanning electron microscopy (SEM) and thermogravimetric analysis (TGA). Moreover, the electrical conductivity and optical properties of the nanocomposites were investigated. Pure (PANI) and the composites containing 2.5 and 5wt% NiFe2O4 showed amorphous structures, while the one with 50wt% NiFe2O4 showed a spinel crystalline structure. The SEM images of the composites showed different aggregations for the different nickel ferrite contents. FTIR spectra revealed to the formation of some interactions between the PANI macromolecule and the NiFe2O4 nanoparticles, while the thermal analyses indicated an increase in the composites stability for samples with higher NiFe2O4 nanoparticles contents. The electrical conductivity of PANI–NiFe2O4 nanocomposite was found to increase with the rise in NiFe2O4 nanoparticle content, probably due to the polaron/bipolaron formation. The optical absorption experiments illustrate direct transition with an energy band gap of Eg=1.0 for PANI–NiFe2O4 nanocomposite.