When we can give access to 'n' processes to share the resource then we can set counting semaphore to an integer 'n' . By giving access one by one to each process we need to decrease the value of counting semaphore. (i.e sometimes it is called as "down" operation or sometimes called as "wait" or sometimes called as "P"). When the value reaches to zero that means CS is full and now if any process comes then decrease the value of counting semaphore and add that process to waiting queue. Now when any process leaves CS, then that waiting process can get access of CS and semaphore value will be increase 1 by 1.
In simple terms, if semaphore value is >= 0 then no processes will be in the waiting queue.
if value is <0 (i.e -n) then n processes will be in the waiting state.