# Why does USB have 4 lines instead of 3?

USB specifies 4 pins:

1.   VBUS   +5V
2.   D-     Data-
3.   D+     Data+
4.   GND    Ground


Why is this not 3? Could the Data and Power not share a common ground? Am I correct in understanding that D- is the ground for D+?

-
Just so you know: There are single-wire protocols where even +5V and data is the same. It won't be fast and interference-safe, but for some applications, less wires is a true net win. Others, like USB and Ethernet, add wires to get more power and data across. –  Macke Sep 27 '11 at 12:34
Wow, this is a surprisingly popular question! –  Rocketmagnet Apr 11 '12 at 11:56

No, D- is not ground. Data is sent over a differential line, which means that D- is a mirror image of D+, so both Data lines carry the signal. The receiver subtracts D- from D+. If some noise signal would be picked up by both wires, the subtraction will cancel it.

So differential signalling helps suppressing noise. So does the type of wiring, namely twisted pair. If the wires ran just parallel they would form a (narrow) loop which could pick up magnetic interference. But thanks to the twists the orientation of the wires with respect to the field changes continuously. An induced current will be cancelled by a current with the opposite sign half a twist further.
Suppose you have a disturbance working vertically on the twisted wire. You could regard each half twist as a small loop picking up the disturbance. Then it's easy to see that the next tiny loop sees the opposite field (upside down, so to speak), so that cancels the first field. This happens for each pair of half twists.
A similar balancing effect occurs for capacitance to ground. In a straight pair one conductor shows a higher capacitance to ground than the other, while in a twisted pair each wire will show the same capacitance.

edit
Cables with several twisted pairs like cat5 have a different twist length for each pair to minimize crosstalk.

-
@pjc50 - Actually, I picked it up from Wikipedia, but if I had to draw it myself I'd use Adobe Illustrator. –  stevenvh Sep 26 '11 at 13:06
@pjc50 or Inkscape, which is the most popular (and really valid) free software alternative –  clabacchio Feb 24 '12 at 9:51
Well, I'm new in electronics. I want to ask you, if the noise was only on the D+, how it could be cancelled? So, I'm saying, is there a situation which the noise is only on the D+ or D-? –  Enes Unal Sep 17 '12 at 8:59
@Enes - That will be negligible due to the symmetry of the wiring: if you take an arbitrary length of wire you can't tell on sight which is D+ and which is D- (apart from the color coding, of course). That means both D+ and D- will be exposed to the disturbance in the same way. And when the noise is the same on both subtracting will cancel it almost completely. –  stevenvh Sep 17 '12 at 9:08
@EnesUnal An interesting point about twisted pair cable is that neither wire is permanently closer to the noise or interference than the other wire. Ref : techtionary.com/members/slides/u/unbalun.swf –  Subin Sebastian Jan 1 at 6:44

It's a differential (or balanced) signal, rather than a single ended (unbalanced) signal.

This means the receiver "measures" the voltage between them, rather than between one and ground.
Say D+ is at 2V, and D- is at 1V. Now say the wire picks up some external noise (RF, mains hum, etc) It is very likely that both cables will pick up the same noise signal since they are twisted together and of the same impedance.
Say we pick up 50mV of noise. So now D+ has 2050mV on it, and D- has 1050mV - the difference between them is still 1V (1000mV) though, and this is what the receiver will "see".
If this had been done with a single ended cable, then D+ (no D-) would be at 1050mV, and ground would still be at 0V, so the receiver would see 1050mV.

This is an bit of an over simplification (but gets the basic concept across) - the ground could also pick up some noise (or have it present to start with), but due to the mismatched impedance between it and the signal the amount of noise picked up on each line will be different and this difference will be seen at the receiving end. Also it may be present initially (e.g. ground loop) which is a big problem for single ended systems.
Matching the impedances of the lines in a balanced connection is very important for good common mode rejection (i.e. rejection of the signal common to both signals) as it only works if both lines pick up exactly the same amount of noise. The signals do not have to be symmetrical. However the noise is created, as long as it affects both signals equally then the common mode rejection will be very good.

-

Actually, that was tried once: The Apple Desktop Bus (ADB) was used to connect keyboards and mice to Apple Macintosh computers from about 1986 until Apple ditched it for USB in 1997 with the iMac.

It had four wires: 5V, ground, data, and power-switch. The power-switch line was just for the power button on the keyboard, which connected the line to ground, and told the power supply to start up the machine. It had to be its own wire so it still worked even if the 5V line was off.

Other than that, the data line carried everything... very slowly. The bus never really progressed beyond being a desktop device bus because it not only had a single-ended signal, but it had length limits (you get reflections off the end of the bus, since it's not terminated at each end).

So Intel decided to use differential signaling for USB. If you want a good idea of what differential signaling buys you, compare the performance in noise of the single-ended RS-232 bus to the differential RS-422 bus. RS-422 can be driven over a longer cable with less source voltage at a given bit error rate.

Why is this? The long version takes a day's lecture in electromagnetics class. The short version is that a noise signal will induce the same voltage in both wires of a differential pair, so the comparator at the receiver end cancels it out (it rejects common-mode voltage very well). A single-ended line has no comparable guarantee, since there's no guarantee that the ground line and signal line will pick up the same noise signal; grounds might even be connected via chassis ground and the return current will take completely different routes.

-
You say RS-422 can be driven longer than RS=232 for a given bit error rate; do long RS-232 cables start to pick up random errors? I would have expected that while there might be some lengths, right on the borderline of usability, where a given message might have a 99% chance of passing through uncorrupted, there wouldn't be much difference between the length where a complex message could pass through with 99% or better chance of success, and the length where it would have a 99% chance of failure. Is the fall-off at all gradual? –  supercat Sep 26 '11 at 15:50
Long RS-232 lines have a big problem that RS-422 does not: Since "ground" is referenced to demodulate the signal, the cumulative error in this "ground" wreaks havoc on the receiver. It gets even worse when the receiver and driver aren't on the same ground (plugged into different power circuits, for example), or when currents other than the signal's return current are on that ground line. Any voltage drop on the ground line, for whatever reason, reduces your noise margin, until it's just gone. Basically, "ground" is a convenient fiction that fails for long cables. –  Mike DeSimone Sep 26 '11 at 17:01
The fall-off is not really that gradual, since in most cases noise is much less than the margin between VOH/VOL and VIH/VIL. What happens is that, at a certain (long length), you start picking up noticeable errors, just as the noise strength starts to equal the receiver threshold (i.e. the voltage needed to bump a 0 to a 1 or vice versa), then as the cable gets longer you get a lot more errors, until it's completely gone. It's not like radio's r^-2 spreading loss. (Back on topic, in ADB's case, the ground wire carries both signal and power return current.) –  Mike DeSimone Sep 26 '11 at 17:06
Is the problem more typically that the noise strength increases, or is the problem more typically that the signal either gets too weak to reach the detection threshold consistently on rising and falling edges? I've certainly seen the latter problem more than noise at high speeds; does noise become the predominant problem at lower speeds (with the longer cable lengths lower speeds would allow)? As for ADB, I think it was designed to save people from having separate wires plug into their PC for the mouse and the keyboard. Too bad modern PC designers don't consider such things. –  supercat Sep 26 '11 at 20:04
In practice, ADB was not that reliable when you had multiple devices. I had a joystick, throttle, keyboard, and mouse, and if you didn't get them in the right order, they would randomly not work. The joystick and throttle were the culprits; they had a lot of cable length built in, and it added up. And, yes, the Mac did not have RS-232 (it's why I used 422 at all), but one trick with RS-422 is that you can convert it to single-ended RS-423 with the cable (TX- becomes TX; TX+ not connected, RX+ to GND, RX- becomes RX), and RS-423 is compatible with RS-232 over short distances. –  Mike DeSimone Sep 27 '11 at 15:54

I can't say definitively that this is the only consideration that went into it, but that's not for grounding, it's for EMI cancellation. The data +/- wires are twisted pair carrying differential signals.

It's just like you'd find in a typical household phone cord or network cable.

-

The D+ D- differential data transmission mechanism is adopted to reduce the noise affected, hence the bandwidth of the transmission can be highly increased.

Like USB there are several other transmission protocol which uses differential physical layer. Some examples are RS485, Ethernet...

-
More examples: en.wikipedia.org/wiki/Differential_signaling#Examples –  starblue Sep 26 '11 at 16:12

Actually a lot of USB has 5 lines, not 4. (The 5th line is for negotiating who is master in OTG applications. Note this is limited to mini and micro USB connectors.)

As others have already pointed out, the D+ and D- lines are a differential pair. Since a receiver can ignore the common mode voltage, a differential pair provides better noise immunity than a single ended signal. Logically, the D+ and D- lines are a single signal.

-
@Kortuk: On mini and micro USB there is a 5th "ID" pin for USB On-the-Go, where either device can act as a host. secure.wikimedia.org/wikipedia/en/wiki/USB#Physical_appearance –  endolith Sep 26 '11 at 15:50
The fifth pin isn't for negotiation as such - it's fixed in the connector and doesn't reach the other end. The idea was to indicate to OTG devices when they need to take the host role by plugging the A end in. There's also a protocol to switch roles, but that's much higher level. –  Yann Vernier May 11 at 7:01

But, even with differential data, there are times when single-ended signaling is used in the USB: The end-of-packet is signaled with a single-ended-zero (SE0), namely, both D+ and D- in low state. This state last the time of 2 bits. if SE0 last for more than 10ms it means a bus reset.

This single-ended signaling makes the USB quite sensitive to electromagnetic interference, like those I found recently when a hair dryer motor was causing a lot of disconnects in a nearby USB peripheral. And no common-mode filters can be effectively used because these can degrade the SE0 signal... Another well conceived standard...

-
Using single-ended signalling for a few conditions that don't require precise timing (e.g. using it for bus reset seems like a perfectly fine idea). Using a two-bit-time SE0 seems a bit quick, though; what are receivers supposed to do if they see a one-bit-time SE0? Having the transmitter send a three-bit-time SE0 and the receiver look for at least two would seem much better. –  supercat Nov 15 '12 at 16:15

Beyond Logic has an overview of the essential points of the electrical portion of the USB spec here (also in PDF format here):

... USB uses a differential transmission pair for data. This is encoded using NRZI and is bit stuffed to ensure adequate transitions in the data stream.

...

The receiver defines a differential ‘1’ as D+ 200mV greater than D- and a differential ‘0’ as D+ 200mV less than D-. The polarity of the signal is inverted depending on the speed of the bus.

-
We appreciate links as an extra, but if the links die your answer becomes useless. Could you give a summary here? –  stevenvh Sep 26 '11 at 10:51
This is a much better answer due to the added summary - Thank you for doing that - but you also need to be careful to avoid plagarism. The content in your first paragraph is copyrighted. –  Kevin Vermeer Sep 26 '11 at 11:43
@KevinVermeer: Quotations are not plagiarism or copyright violation. –  endolith Sep 26 '11 at 14:14
@endolith - With attribution, they're not plagarism or copyright violation. I've edited the answer to demonstrate better attribution. Previously, no one would have known that the paragraph was mostly a quotation. Now it's obvious. When making a quotation, use the block quote features. –  Kevin Vermeer Sep 26 '11 at 14:48