An optimal positioning algorithm based on polynomial fitting technique for non-line-of-sight (NLOS) environment is presented. First, NLOS errors in TOA measurements are mitigated using an orthogonal polynomial fitting technique. Then the standard deviation of LOS error is exploited to give an optimal location estimation of the mobile station (MS). Performance measure for location accuracy is calculated and comparison with least squares (LS) algorithm, constrained weighted least squares (CWLS) algorithm and Cramér-Rao lower bound (CRLB) in LOS environment is also given. Simulation results show that our proposed algorithm can achieve better location estimation in NLOS environment.