A dog who rests in a crate on some nights and barks hard on others may be telling you something changed. Toileting, pain, temperature, noise, the day's activity or being apart from people can all matter. Do not assume the barking is a trick to win attention. Nor should the crate become a place where a frightened dog must stay until silent.
Meet the need, then change the setup
Check whether your dog needs a toilet break, water or a more comfortable resting place. If the barking is new, intense, or comes with panting, drooling, frantic escape attempts or self-injury, contact your veterinarian and use a safe alternative to confinement. A dog who hurts themselves trying to get out needs an individual plan, not another cry-it-out night.
During the day, notice whether your dog freely chooses to enter the crate and rest there. If not, rebuild comfort with the door open and brief voluntary visits. You can also try a safe sleeping place closer to you if that helps your dog rest. Bedtime barking alone is not a diagnosis of separation anxiety. If daytime observations also show distress whenever your dog is separated, the home-alone distress guide offers a dog-paced plan to review alongside veterinary or qualified behavior support.
Keep a small log of the difficult nights: what happened before bed, when the barking started and whether your dog needed something. Use it to change one part of the routine rather than testing how long they can bark.
Sources: Dogs Trust on making crates and pens comfortable, never punishment. VCA on barking patterns and causes.