Quality of service (QoS) is one of the critical aspects for real-time applications in wireless local area networks (WLANs). To provide QoS, WLANs use the enhanced distributed channel access (EDCA) with a fixed backoff range without considering the network load for estimating the backoff time. When the number of stations (STAs) increases in each access category (AC), the collision among STAs also increases; this leads to increased delay and decreased network throughput. In this paper, we aim to improve the QoS for WLANs and achieve better network performance in terms of high throughput, low collision rate, and small mean frame delay in delay-sensitive applications. To achieve this objective, we propose an adaptive contention window backoff mechanism that improves the QoS by adjusting the backoff time according to the active STAs in each AC. First, we estimate the number of STAs in each AC and then calculate the optimal contention window size based on the estimated STAs in each AC. We derived an analytical model for the proposed scheme and then conducted simulations to validate analytical model results. The simulation results show that the proposed scheme outperforms EDCA in terms of throughput and delay in different traffic scenarios.