Niobium provides the basis for all superconducting radio frequency cavities in use. However, flux pinning at lattice imperfections significantly contributes to degradation in niobium performance at high radio frequency accelerating fields. Lattice defects, such as dislocations and grain boundaries, pin the field inside the material even after the external magnetic field is removed thereby increasing the cavity surface resistance and decreasing the cavity quality factor. Several theories had been proposed to explain the flux trapping at defects, but the mechanism(s) underlying the flux pinning has not been unequivocally established. Therefore, to understand the relationship between lattices defects and flux-trapping in niobium first-principles methods were employed. The all-electron full-potential linearized augmented plane wave (FP-LAPW) code was used to analyze magnetic flux trapping at niobium grain boundaries within the first-principles framework. The external magnetic field was applied along the lattice defects and reduced after each self-consistent loop such that the applied field is zero at the end of all loops. A significant amount of flux trapping was observed at dislocation core and different types of symmetric tilt grain boundaries in niobium. Furthermore, the electronic density of states calculations and Bader charge analysis illustrates that the flux trapping at defects in niobium can be attributed to charge redistribution and splitting of d states at the defects, which enhance niobium’s tendency towards magnetism.