Work out which of three situations you are in before changing anything: one port dead, all ports dead, or a device that connects and drops off. Each has a different likely cause.
Step 1 — Confirm it is the port, not the device
Test the same device on a port you know works, and test a known-good device on the suspect port. If the device fails everywhere, the device is the problem. If it fails on one port only, the port is the problem.
Shine a torch into the port and look for bent pins, lint and debris. Lint packed into a phone or laptop port is the single most common cause of "the cable does not fit anymore". A wooden toothpick is the right tool — never metal.
Step 2 — One port dead
- Restart. Ports get disabled by a failed enumeration and come back on reboot.
- Open Device Manager → View → Show hidden devices → Universal Serial Bus controllers. Look for greyed or warning-marked entries, uninstall them, and restart.
- On a desktop, that one port may be on a front-panel header that has worked loose from the motherboard. Reseat the header if you are comfortable opening the case.
- If the port is physically loose or the device only works when you hold the cable at an angle, the port is damaged. A desktop can use a cheap PCIe USB card instead of a board repair; a laptop needs a board-level repair, which is rarely worth it.
Step 3 — All ports dead
- Test in BIOS/UEFI. If the keyboard works there but not in Windows, this is a software problem, not hardware.
- Uninstall the whole USB host controller group in Device Manager and restart. Windows rebuilds the stack.
- Check Power Management: Device Manager → USB Root Hub → Properties → Power Management → untick Allow the computer to turn off this device to save power. Do this for each root hub.
- On a desktop, a failing power supply or a loose 24-pin connector can cause USB dropouts. If USB dies under load, suspect the PSU.
Step 4 — Device connects and disconnects
- Swap the cable. Cables fail more often than devices, especially at the connector.
- Avoid unpowered hubs. An external drive that draws more than the hub can supply will drop off whenever it spins up. Use a powered hub or a rear port.
- Update the device's driver from the manufacturer, not from a driver-updater site.
- For a device that worked yesterday, try System Restore to a point before the change.
When it is the port hardware
A desktop front port that has never worked is usually a header that was never connected. A desktop port that suddenly died is usually a dead controller on the board — a $15 USB card is the pragmatic fix. On a laptop, a single dead port with the rest working is usually not worth repairing; carry a small hub instead.